Back
Close

Various Number Spirals

Statement

 Goal

You should print out a spiral of numbers from 1 to n^2 or vice versa starting from the defined corner and in clockwise or counter-clockwise order with tabulation (\t) as separator.

For descending order the corner in input marks the place where the n^2 should be
Input
Line 1: An integer n for the spiral size
Line 2: two space-separated letters v h to mark the starting point ( v is 't' for top or 'b' for bottom, h is 'l' for left or 'r' for right)
Line 3: two space-separated values o and d to mark order of numbers and direction, where o is '+' for ascending order of numbers or '-' for descending, and d is 'c' for clockwise and 'cc' for counter-clockwise order
Output
n lines: the tab-separated spiral of numbers
Constraints
1 ≤ n ≤ 10
Example
Input
3
t l
+ c
Output
1	2	3
8	9	4
7	6	5

Tags
Loops

Difficulty
Medium

Test cases
Example Test
Input
3 t l + c
Output
1 2 3 8 9 4 7 6 5

Validator 1 Validator
Input
3 b l + c
Output
3 4 5 2 9 6 1 8 7

Counter-clockwise Test
Input
4 b l + cc
Output
10 9 8 7 11 16 15 6 12 13 14 5 1 2 3 4

Validator 2 Validator
Input
4 b r - cc
Output
10 11 12 13 9 2 3 14 8 1 4 15 7 6 5 16

Primitive Test
Input
1 b r + c
Output
1

Validator 3 Validator
Input
1 b r - cc
Output
1

Big one Test
Input
10 t r + c
Output
28 29 30 31 32 33 34 35 36 1 27 58 59 60 61 62 63 64 37 2 26 57 80 81 82 83 84 65 38 3 25 56 79 94 95 96 85 66 39 4 24 55 78 93 100 97 86 67 40 5 23 54 77 92 99 98 87 68 41 6 22 53 76 91 90 89 88 69 42 7 21 52 75 74 73 72 71 70 43 8 20 51 50 49 48 47 46 45 44 9 19 18 17 16 15 14 13 12 11 10

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

Descending Test
Input
5 t l - c
Output
25 24 23 22 21 10 9 8 7 20 11 2 1 6 19 12 3 4 5 18 13 14 15 16 17

Validator 5 Validator
Input
7 t r - cc
Output
43 44 45 46 47 48 49 42 21 22 23 24 25 26 41 20 7 8 9 10 27 40 19 6 1 2 11 28 39 18 5 4 3 12 29 38 17 16 15 14 13 30 37 36 35 34 33 32 31

Solution language

Solution

Stub generator input