-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspiral.py
68 lines (48 loc) · 777 Bytes
/
spiral.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
##âûâîäèò N-ðàçìåðíóþ ñïèðàëü óâåëè÷èâàþùèõñÿ ÷èñåë
n = int(input())
b=[[0 for i in range(n)] for j in range(n)]
z=0
bi=0
bj=1
ei=n
ej=n
i=0
j=0
istep =1
jstep =1
fin=False
while not fin:
if ei-bi == 0 and ej-bj == 0 :
break
for i in range(bi,ei,istep):
z +=1
b[j][i]=z
if bi<ei:
bi1=bi
bi =i-1
ei = bi1-1
istep =-1
else:
bi1=bi
bi =i+1
ei =bi1+1
istep =1
if ei-bi == 0 and ej-bj == 0 :
break
for j in range(bj,ej,jstep):
b[j][i]=z+1
z+=1
if bj<ej:
bj1=bj
bj =j-1
ej = bj1-1
jstep =-1
else:
bj1=bj
bj =j+1
ej =bj1+1
jstep =1
for k in range(len(b)):
for d in range(len(b[k])):
print(b[k][d], end=' ')
print()