diff --git a/28/main.py b/28/main.py new file mode 100644 index 0000000..1851ccc --- /dev/null +++ b/28/main.py @@ -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() \ No newline at end of file