That one was easy
This commit is contained in:
31
28/main.py
Normal file
31
28/main.py
Normal 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()
|
||||||
Reference in New Issue
Block a user