Back
Close
  • 31

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

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

A higher resolution is required to access the IDE