Problems
Given the height π of a triangle, write a program that fills the triangle in a snail (spiral) pattern with numbers from 0, as shown below.
Conditions
Start from the top-left and move diagonally down to the right, filling numbers from 0 up to π.
Then move to the left, and then upward, repeating this clockwise spiral pattern.
After 9, continue numbering from 0 again.
Input
A single integer π is given, representing the length of one side of the triangle.
π is a positive integer not exceeding 100.
Output
Print the snail-shaped triangle with height
Separate numbers with a single space.
Example #1
3
0
5 1
4 3 2
Example #2
4
0
8 1
7 9 2
6 5 4 3
Example #3
6
0
4 1
3 5 2
2 0 6 3
1 9 8 7 4
0 9 8 7 6 5
Tag
Source
JUNGOL