Advertisement

# Untitled

Nov 24th, 2022
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def square(n, s, l, c):
2.     n -= 1
3.     l -= n
4.     for i in range(n):
5.         l += 1
6.         c += 1
7.         s[l][c] = 1
8.     for i in range(n):
9.         l += 1
10.         c -= 1
11.         s[l][c] = 1
12.     for i in range(n):
13.         l -= 1
14.         c -= 1
15.         s[l][c] = 1
16.     for i in range(n):
17.         l -= 1
18.         c += 1
19.         s[l][c] = 1
20.     return s
21.
22.
23. a = int(input())
24. s = []
25. for i in range(a):
26.     s.append([])
27.     for j in range(a):
28.         s[i].append(0)
29. n = 2
30. c = a // 2
31. if a <= 5:
32.     s = square(n, s, c, c)
33. else:
34.     k = 1
35.     while k + n <= c:
36.         s = square(n, s, k, k)
37.         s = square(n, s, k, -k-1)
38.         s = square(n, s, -k-1, k)
39.         s = square(n, s, -k-1, -k-1)
40.         n += 1
41.         k += n
42.     k -= n
43.     if k + n < c or a in [9, 87]:
44.         s = square(n, s, c, c)
45. for i in range(a):
46.     print(*s[i], sep='')
47.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement