forked from SPerez26/Project_Euler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEuler28.py
43 lines (33 loc) · 902 Bytes
/
Euler28.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
#Problem28
spiral_side = 1001
size = spiral_side**2
diagonal = []
counter = 0
start = 3
step = 2
end = (start + step*3) + 1
while counter < size:
for i in range(start,end,step):
#counter += 1
#print(i,start,step,end,counter)
#if counter == 25:
#break
diagonal.append(i)
counter = i
step +=2
start = i + step
end = (start + step*3) + 1
#print("END","Counter:",counter)
diagonal1 = []
diagonal2 = []
for i in range(1,len(diagonal)+1,2):
diagonal1.append(diagonal[i])
for i in range(0,len(diagonal),2):
diagonal2.append(diagonal[i])
diagonal1.append(1)
diagonal2.append(1)
diagonal1.sort(reverse=False)
diagonal2.sort(reverse=False)
#print(diagonal1)
#print(diagonal2)
print(f"Sum of numbers in diagonals: {sum(diagonal1)+sum(diagonal2)-1}")