Project Euler 6
You are asked to find the difference between the square of the sum and the sum of the squares of the first 100 natural numbers. So: (1 + 2 + ... + 99 + 100)^2 - (1^2 + 2^2 + ... + 99^2 + 100^2). This is trivially easy to brute force on a computer, especially with the range(1,101) function in python. Two loops will get you a solution in practically no time. Alternatively, a reduce and a map & reduce will get you there in no time too. However, this problem is actually probably faster to just do by hand. To the best of my knowledge, this is the first one of the Project Euler problems that is like this. You just need to be familiar with two famous series in mathematics. I have the 1 + 2 + ... + 99 + 100 series internalized, it is simply n(n+1)/2. I had to look up the 1^2 + 2^2 + ... + 99^2 + 100^2 power series, but the formula is n(n+1)(2n+1)/6. Here's the code I wrote since I wanted something I could save in my Project Euler folder.
# Two famous series def sum_of_squares(n): return (n)*(n+1)*(2*n+1)/6 def square_of_sum(n): return (n*(n+1)/2)**2 def main(n): return sum_of_squares(n) - square_of_sum(n)













