From 7704151504d38433bb7490298576dfbb604280b6 Mon Sep 17 00:00:00 2001 From: Daniel Ingram Date: Wed, 14 Mar 2018 16:03:44 -0400 Subject: [PATCH] Solution to Problem 28 --- Project Euler/Problem 28/sol1.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Project Euler/Problem 28/sol1.py diff --git a/Project Euler/Problem 28/sol1.py b/Project Euler/Problem 28/sol1.py new file mode 100644 index 000000000..7944caa21 --- /dev/null +++ b/Project Euler/Problem 28/sol1.py @@ -0,0 +1,23 @@ +from __future__ import print_function + +def diagonal_sum(n): + total = 1 + + for i in xrange(n/2): + odd = 2*(i+1)+1 + even = 2*(i+1) + total = total + 4*odd**2 - 6*even + + return total + +if __name__ == '__main__': + import sys + + if len(sys.argv) == 1: + print(diagonal_sum(1001)) + else: + try: + n = int(sys.argv[1]) + diagonal_sum(n) + except ValueError: + print('Invalid entry - please enter a number') \ No newline at end of file