Commits

Ian Lewis committed ae5c5a5

Added solution for problem 6 (Python)

Comments (0)

Files changed (1)

+"""
+The sum of the squares of the first ten natural numbers is,
+
+1**2 + 2**2 + ... + 102 = 385
+The square of the sum of the first ten natural numbers is,
+
+(1 + 2 + ... + 10)**2 = 55**2 = 3025
+Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025  385 = 2640.
+
+Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
+"""
+
+X = 100
+
+def squares(start, stop, step=1):
+    x = start
+    while x < stop:
+        yield x**2
+        x += step
+
+def euler6(x):
+    sum_of_squares = sum(squares(1, x+1))
+    square_of_sum = sum(xrange(1, x+1))**2
+    return square_of_sum - sum_of_squares
+
+if __name__ == '__main__':
+    print euler6(X)