-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.py
49 lines (40 loc) · 1.07 KB
/
main.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
n = int(input())
width = (2 ** (n+1)) - 3
hieght = (2 ** n) - 1
stars = [[' '] * width for _ in range(hieght)]
def sol(n, r, c):
w = (2 ** (n+1)) - 3
h = (2 ** n) - 1
if n == 1:
stars[r][c] = '*'
return
if n % 2 == 0:
stars[r][c] = '*'
for i in range(h):
stars[r-i][c-i] = '*'
stars[r-i][c+i] = '*'
for i in range(w):
stars[r-(h-1)][c - (w-1)//2 + i] = '*'
sol(n - 1, r-(h-2), c)
else:
stars[r][c] = '*'
for i in range(h):
stars[r + i][c - i] = '*'
stars[r + i][c + i] = '*'
for i in range(w):
stars[r + (h - 1)][c - ((w - 1) // 2) + i] = '*'
sol(n - 1, r + (h-2), c)
def printstar(stars):
for star in stars:
print(''.join(star))
if n % 2 == 0:
sol(n, hieght - 1, width//2)
for i in range(1, hieght):
for _ in range(i):
stars[i].pop()
else:
sol(n, 0, width // 2)
for i in range(1, hieght):
for _ in range(i):
stars[hieght-1-i].pop()
printstar(stars)