Advertisement
Guest User

Untitled

a guest
Aug 1st, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. n = int(input())
  2. t = 1
  3. a = []
  4. for i in range(n):
  5. a.append([])
  6. for j in range(n):
  7. a[i].append(0)
  8. for i in range(n):
  9. a[0][i] = t
  10. t += 1
  11. t -= 1
  12. z = 0
  13. i = 0
  14. j = n-1
  15. for x in range(n*2 - 2):
  16. if x % 4 == 0:
  17. z += 1
  18. for y in range(n - z):
  19. i += 1
  20. t += 1
  21. a[i][j] = t
  22. elif x % 4 == 1:
  23. for y in range(n - z):
  24. j -= 1
  25. t += 1
  26. a[i][j] = t
  27. elif x % 4 == 2:
  28. z += 1
  29. for y in range(n - z):
  30. i -= 1
  31. t += 1
  32. a[i][j] = t
  33. elif x % 4 == 3:
  34. for y in range(n - z):
  35. j += 1
  36. t += 1
  37. a[i][j] = t
  38.  
  39. for i in range(n):
  40. for j in range(n):
  41. print(a[i][j], end=" ")
  42. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement