2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
id: 5900f3881000cf542c50fe9b
|
|
|
|
|
challengeType: 5
|
|
|
|
|
videoUrl: ''
|
2020-10-01 15:54:21 +00:00
|
|
|
|
title: 问题28:对角螺旋数
|
2018-10-10 22:03:03 +00:00
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## Description
|
2020-02-17 16:40:55 +00:00
|
|
|
|
<section id="description">
|
|
|
|
|
从数字1开始,沿顺时针方向向右移动,形成5 x 5螺旋,如下所示:
|
|
|
|
|
21 22 23 24 25
|
|
|
|
|
20 7 8 9 10
|
|
|
|
|
19 6 1 2 11
|
|
|
|
|
18 5 4 3 12
|
|
|
|
|
17 16 15 14 13
|
|
|
|
|
可以验证对角线上的数字之和为101。
|
|
|
|
|
以相同方式形成的n×n螺旋中的对角线上的数字的总和是多少?
|
|
|
|
|
</section>
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
|
|
## Instructions
|
2020-02-17 16:40:55 +00:00
|
|
|
|
<section id="instructions">
|
|
|
|
|
</section>
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
<section id='tests'>
|
|
|
|
|
|
|
|
|
|
```yml
|
|
|
|
|
tests:
|
2020-02-17 16:40:55 +00:00
|
|
|
|
- text: '<code>spiralDiagonals(101)</code>应该返回692101。'
|
|
|
|
|
testString: assert(spiralDiagonals(101) == 692101);
|
|
|
|
|
- text: '<code>spiralDiagonals(101)</code>应该返回18591725。'
|
|
|
|
|
testString: assert(spiralDiagonals(303) == 18591725);
|
|
|
|
|
- text: '<code>spiralDiagonals(101)</code>应该返回85986601。'
|
|
|
|
|
testString: assert(spiralDiagonals(505) == 85986601);
|
|
|
|
|
- text: '<code>spiralDiagonals(101)</code>应该返回669171001。'
|
|
|
|
|
testString: assert(spiralDiagonals(1001) == 669171001);
|
2018-10-10 22:03:03 +00:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Challenge Seed
|
|
|
|
|
<section id='challengeSeed'>
|
|
|
|
|
|
|
|
|
|
<div id='js-seed'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
function spiralDiagonals(n) {
|
|
|
|
|
// Good luck!
|
|
|
|
|
return n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spiralDiagonals(1001);
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
## Solution
|
|
|
|
|
<section id='solution'>
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
// solution required
|
|
|
|
|
```
|
2020-08-13 15:24:35 +00:00
|
|
|
|
|
|
|
|
|
/section>
|