Problem 6#
from project_euler import get_problem_description
get_problem_description(6)
The sum of the squares of the first ten natural numbers is,
$$1^2 + 2^2 + ... + 10^2 = 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.
def sum_of_squares(numbers):
return sum((num**2 for num in numbers))
def square_of_sum(numbers):
return sum(numbers) ** 2
numbers = range(11)
assert sum_of_squares(numbers) == 385
assert square_of_sum(numbers) == 3025
numbers = range(101)
square_of_sum(numbers) - sum_of_squares(numbers)
25164150