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
"""
*FRIDAY CHALLENGE* : write a code that gets as input a positive number N > 1 and prints a N x N CLOCKWISE-SPIRAL-SQUARE
Example:
if N=3 then the Clockwise Spiral Square looks like this:
1 2 3
8 9 4
7 6 5
"""
def right(num, index, cycle):
if num == n*n+1: return
try:
if lst[cycle][index] == 0:
lst[cycle][index] = num
right(num+1, index+1, cycle)
else:
down(num, cycle+1, cycle)
except:
down(num, cycle+1, cycle)
def down(num, index, cycle):
if num == n*n+1: return
try:
if lst[index][n-(cycle+1)] == 0:
lst[index][n-(cycle+1)] = num
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run