-
Notifications
You must be signed in to change notification settings - Fork 0
/
028.py
31 lines (27 loc) · 769 Bytes
/
028.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
# ----------------------------------
# Project Euler - projecteuler.net
# ----------------------------------
# Developed by Felipe B Oriani
# 028 - Number spiral diagonals
# What is the sum of the numbers on the diagonals in a 1001 by 1001 spiral formed in the same way?
# ----------------------------------
def f(n):
s = 1
count = 0
jump = 1
countJump = 1
for i in range(2, n*n+1):
if count < jump:
count += 1
elif count == jump:
count = 0
s += i
if countJump == 4:
jump += 2
countJump = 1
else:
countJump += 1
return s
anwser = f(1001)
assert anwser == 669171001
print 'Answer: ', anwser