That one was easy

This commit is contained in:
2020-11-08 22:45:13 +01:00
parent 0e365c99eb
commit da71c9def7

31
28/main.py Normal file
View File

@@ -0,0 +1,31 @@
# Number spiral diagonals
# Find the sum of the numbers on the diagonals of a 1001 by 1001 spiral
def sumSpiralDiagonals(n):
assert n % 2 == 1
if n == 1:
return 1
result = 0
corner = 1
for i in range(1, n+1, 2):
if i == 1:
result += corner
else:
for j in range(4):
corner += i - 1
result += corner
return result
def main():
print("Hello, this is Patrick")
print(sumSpiralDiagonals(1001))
if __name__ == "__main__":
main()