With this one being perhaps my favourite problem yet, I had to solve it twice! Feel free to download my solution and take a look, or read below to see my mathematical approach to the problem.
Euleryx Problem 6 - Sum Square Difference

My workflows and answer:
Spoiler

Answer:
25164150
Last Weeks Favourite Solution:
After another prime number related challenge last week there was such a range of approaches. With a 3 tool solution that managed to take advantage of both the message tool, and "Cancel Running Workflow on Error" Runtime setting, our favourite solution was by @AkimasaKajitani. Having never seen the message tool used in such a practical manner, we had to cast a spotlight on this solution. Find it on page one of last weeks post, or click here.
Definitions:
On the face of it this problem doesn’t seem to be complicated; however, depending on your route to a solution, there are some key concepts we must first introduce.
- Square: A number multiplied by itself
- Sequence: A list of numbers arranged in a specific order, typically defined by a rule or formula.
- Series: A series is the sum of the terms in a sequence.
- General term: (sometimes called the nth term) is a formula that allows you to compute any term in a sequence, based solely on its position. (i.e. if your sequence is even numbers, 2, 4, 6 …. The general term would 2n, therefore to find the 20th term, you would set n = 20, then calculate 2 * 20. Hence the 20th term = 40)
Mathematical Theory:

Let's begin by taking a look at a series. As mentioned above, a series is the sum of the terms in a sequence. This can be expressed mathematically by defining the following values:
- Index (term value): k
- Ending value: n
- General term:
, (think of it like a function, just like you might have y = 2x + 1 as a function,
= 2k + 1, is also a function)
The formula then looks something like this:

Which simply reads, sum all the terms in your sequence, beginning at 0 and ending at n.
To give an example, lets look at one of the simplest cases, called the Arithmetic Series. The sequence here is simply 1, 2, 3, 4, 5….., n. There for the general term is simply expressed as
= k. So the series can be expressed as:

If you were asked to calculate the sum of the first 5 terms of this sequence, you could write:

Therefore, we get the answer, 15. But what if you were asked to find the sum of the first 100 or even 1000 terms? That’s where the trick to this problem comes in. Some series have special formulas to help us find this sum quickly. Here are some useful examples:
Arithmetic series:

Quadratic series (square numbers):

But do these actually work?
Well, we can check the equation for the Arithmetic series, by using the same example as earlier.

Which is the same answer as we got before!

Whilst I won't cover the proofs in this post, if you're interested, I encourage you to explore the series further. There is a brief description provided by Project Euler upon submission of a correct answer.
Method:
Using what we have just learnt, the method for this week's problem actually becomes incredibly simple: so simple, it can pretty much be achieved in a single formula tool.
- Enter the value we want to sum up to. In this case, 100 (as specified by the question).

- Enter the formula we have just learnt into the formula tool, I,e:
Sum of Squares:

Square of Sum:


- Subtract the sum of squares from the squared sum to reveal your answer.

- Submit your answer to the Project Euler Website!

Summary:
Whilst the brute force method here is still relatively quick, by applying some mathematical theory surrounding series, we have been able to get an answer in just one tool, and one row of data!
Want to find out more, follow this link to our introduction post - Euleryx: Let The Games Begin.