Back
Close

Snail

Statement
The program:
Your program must fill a grid with numbers, starting at 1 from the top left corner, going right and then spiralling down towards the center.
Numbers below 10 must be prefixed with 0 so that all numbers are two characters wide.
INPUT:
Line 1:W and H, the width and height of the grid.

OUTPUT:
[H] lines: W numbers, padded to two chars with 0 and separated by spaces.

CONSTRAINTS:
1<=W
1<=H
W*H<100

EXAMPLE:
Input
3 4
Output
01 02 03
10 11 04
09 12 05
08 07 06
 

Game modes
Fastest, Shortest, Reverse

Test cases
Simple Test
Input
3 4
Output
01 02 03 10 11 04 09 12 05 08 07 06

Validator 1 Validator
Input
4 3
Output
01 02 03 04 10 11 12 05 09 08 07 06

Square Test
Input
5 5
Output
01 02 03 04 05 16 17 18 19 06 15 24 25 20 07 14 23 22 21 08 13 12 11 10 09

Validator 2 Validator
Input
9 9
Output
01 02 03 04 05 06 07 08 09 32 33 34 35 36 37 38 39 10 31 56 57 58 59 60 61 40 11 30 55 72 73 74 75 62 41 12 29 54 71 80 81 76 63 42 13 28 53 70 79 78 77 64 43 14 27 52 69 68 67 66 65 44 15 26 51 50 49 48 47 46 45 16 25 24 23 22 21 20 19 18 17

Large Test
Input
9 11
Output
01 02 03 04 05 06 07 08 09 36 37 38 39 40 41 42 43 10 35 64 65 66 67 68 69 44 11 34 63 84 85 86 87 70 45 12 33 62 83 96 97 88 71 46 13 32 61 82 95 98 89 72 47 14 31 60 81 94 99 90 73 48 15 30 59 80 93 92 91 74 49 16 29 58 79 78 77 76 75 50 17 28 57 56 55 54 53 52 51 18 27 26 25 24 23 22 21 20 19

Validator 3 Validator
Input
3 33
Output
01 02 03 68 69 04 67 70 05 66 71 06 65 72 07 64 73 08 63 74 09 62 75 10 61 76 11 60 77 12 59 78 13 58 79 14 57 80 15 56 81 16 55 82 17 54 83 18 53 84 19 52 85 20 51 86 21 50 87 22 49 88 23 48 89 24 47 90 25 46 91 26 45 92 27 44 93 28 43 94 29 42 95 30 41 96 31 40 97 32 39 98 33 38 99 34 37 36 35

One-liner Test
Input
1 17
Output
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17

Validator 4 Validator
Input
35 1
Output
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

Solution language

Solution

Stub generator input