Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- t = 1
- a = []
- for i in range(n):
- a.append([])
- for j in range(n):
- a[i].append(0)
- for i in range(n):
- a[0][i] = t
- t += 1
- t -= 1
- z = 0
- i = 0
- j = n-1
- for x in range(n*2 - 2):
- if x % 4 == 0:
- z += 1
- for y in range(n - z):
- i += 1
- t += 1
- a[i][j] = t
- elif x % 4 == 1:
- for y in range(n - z):
- j -= 1
- t += 1
- a[i][j] = t
- elif x % 4 == 2:
- z += 1
- for y in range(n - z):
- i -= 1
- t += 1
- a[i][j] = t
- elif x % 4 == 3:
- for y in range(n - z):
- j += 1
- t += 1
- a[i][j] = t
- for i in range(n):
- for j in range(n):
- print(a[i][j], end=" ")
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement