PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#Prints an inward spiral square counting from 1 - N*N, N being the size of the spiral square.
import math
import sys
#Inserts the top row of current traversal, returning the current count.
def top(spiral, count, trav, size):
tmp = trav
while tmp <= size-trav-1:
spiral[trav][tmp] = count
count += 1
tmp += 1
return count
#Inserts the right column of current traversal, returning the current count.
def right(spiral, count, trav, size):
tmp = trav+1
while tmp <= size-trav-1:
spiral[tmp][size-trav-1] = count
count += 1
tmp += 1
return count
#Inserts the bottom row of current traversal, returning the current count.
def bottom(spiral, count, trav, size):
tmp = size-trav-2
while tmp >= trav:
spiral[size-trav-1][tmp] = count
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run