-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path28.py
78 lines (71 loc) · 1.65 KB
/
28.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
69
70
71
72
73
74
75
76
77
78
import time
def is_diagonal(x, y, n):
if x == y:
return True
elif x + y == n - 1:
return True
return False
def make_spiral(n):
# n - razmer spirali.
# Inicializirovat' spisok spiskov.
a = []
for noli in xrange(n):
a.append([])
for i in xrange(n):
a[noli].append(0)
# Postavit' edinicu
center = (n-1)/2
a[center][center] = 1
px = center
py = center
cifra = 1
for krug in xrange(center):
if krug % 100 == 0:
print krug
# Postavit' cifri iz sleduyushego kruga.
cifra +=1
px += 1
a[py][px] = cifra
while not is_diagonal(px, py, n):
py +=1
cifra += 1
a[py][px] = cifra
px -= 1
cifra +=1
a[py][px] = cifra
while not is_diagonal(px, py, n):
px -=1
cifra += 1
a[py][px] = cifra
cifra +=1
py -= 1
a[py][px] = cifra
while not is_diagonal(px, py, n):
py -=1
cifra += 1
a[py][px] = cifra
px += 1
cifra +=1
a[py][px] = cifra
while not is_diagonal(px, py, n):
px +=1
cifra += 1
a[py][px] = cifra
'''s = 0
for i in xrange(n):
for j in xrange(n):
if is_diagonal(i, j, n):
s += a[i][j]
print "per",s'''
s = -1
for i in xrange(n):
s += a[i][i]
ii = 0
for j in xrange(n-1,-1,-1):
s += a[ii][j]
ii +=1
print s
n = time.time()
make_spiral(1001)
k = time.time()
print k - n