We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 6 - Sum Square Difference

Pilsner
13 - Pulsar

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

Pilsner_15-1756992824130.png

 

 

My workflows and answer:

Spoiler
Pilsner_0-1756992608369.png

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:

MathHangoverGIF.gif

 

 

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: Pilsner_1-1756993648695.png, (think of it like a function, just like you might have y = 2x + 1 as a function, Pilsner_1-1756993648695.png = 2k + 1, is also a function) 

     

 

The formula then looks something like this:

Pilsner_2-1756992608491.png

 

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 Pilsner_2-1756993661131.png=  k. So the series can be expressed as:

 

Pilsner_3-1756992608491.png

 

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

Pilsner_4-1756992608491.png

 

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:

Pilsner_5-1756992608492.png

 

Quadratic series (square numbers):

 

Pilsner_6-1756992608492.png

 


But do these actually work?

Well, we can check the equation for the Arithmetic series, by using the same example as earlier.

 

 

Pilsner_7-1756992608492.png

 

Which is the same answer as we got before! 

 

 

JurassicParkAlanGrantGIF.gif

 

 

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.

 

  1. Enter the value we want to sum up to. In this case, 100 (as specified by the question).
    Pilsner_9-1756992608555.png

  2. Enter the formula we have just learnt into the formula tool, I,e:

    Sum of Squares:

    Pilsner_10-1756992608556.png

     

    Square of Sum:

    Pilsner_11-1756992608557.png

     

     

    Pilsner_12-1756992608558.png





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

    Pilsner_13-1756992608559.png

  4. Submit your answer to the Project Euler Website!

    CompletedCompletedItMateGIF.gif

 

 

 

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.

 

11 REPLIES 11
CoG
14 - Magnetar

Nicely done, @Pilsner  with the closed form! I did not think about that approach at all. I got close (coincidentally following a very similar approach to @gawa! Did find the Triangle Numbers which helped simplify things a little bit:

 

Spoiler
Screenshot 0006-1.png
Carolyn
12 - Quasar
12 - Quasar

@CoG - I'm excited to see how long you can solve the problems with, basically, just a Generate Rows tool. I'm saying you can make it through Day 27

Labels
Top Solution Authors