31 lines
490 B
Python
31 lines
490 B
Python
# 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() |