ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 9 - Special Pythagorian Triplet

Pilsner
13 - Pulsar

Euleryx Problem 9 - Special Pythagorean Triplet



Pilsner_0-1759100287914.png

 

 

My workflow and answer:

Spoiler
Pilsner_1-1759100387140.png


Answer: 31875000

 


Last Weeks Favourite Solution:
@Carolyn realised that, in last weeks problem, we could treat 0s as delimiters. Because a 0 minimises the multiplications, we don’t even need to compute lists containing them. Although this may sound counter intuitive to some, assumptions are also a key part of mathematics. @Carolyn  made an educated assumption that other small integers could be treated as delimiters too, drastically reducing the computation required to get to a solution. There were some great replies but this was our favourite solution from last week. If you want to check out this solution, please view it on page one of last weeks post or by clicking here.

 

Mathematical Theory:

 

 This week we are again going to look into bounds, to help restrict the amount of data we need to process. Whilst it is possible to simply generate 1000 rows each for a, b and c, appending these would lead to 1,000,000,000 rows of data (which is no small value). So lets see what we can do to reduce the volume of data we deal with.

CatCatMathGIF.gif

 

Firstly, we can figure out the maximum value for one of the variables. Lets begin with “a”. We know that our variables are integers and that:

 

a < b < c              therefore             a + 1 <= b            (as b has to be an integer bigger than a)

 

Following similar logic:

 

b < c      therefore            b + 1 <= c              therefore            a + 2 <=c

 

Using the above, it should be evident that the smallest possible value for b, is a + 1, and the smallest possible value of c, is a + 2.

 

Now, we also know that a + b + c = 1000. If we can use this to find the largest possible value for a, we will have our upper bound. ‘a’ will be at its largest value, when b and c are at their smallest, so lets set them equal to their smallest value. After some simple substitution, we get:

 

a + (a + 1) + (a + 2) = 1000           which equals    3a + 3 = 1000

 

After some simple rearrangement, we are left with  a = 332.333.. As we were calculating the largest possible value of a, and we know the variables are all integers, we could write a <= 332. We now have a upper bound for a!

 

The lower bound is a bit trickier but, as proven in some of the solutions last week,  an educated assumption can be very valuable. I assumed that all the numbers would be in the triple digits, hence I set the lower bound for a as a > = 100. This means that we only need to generate values for a where the following is true:

 

100 <= a <= 332

 

ItKindaMakeSenseElvisTheAlienGIF.gif

 

Once we have generated the values for a, we can generate the values for b. The lower bound is simple. As a < b, the lower bound for b, is simply the value for a; the upper bound is a bit more complicated. To begin with, we know that:

 

a + b + c = 1000               therefore            1000 – a = b + c

 

Similarly to before, b will be at its greatest when c is at is smallest (Remember a is already calculated/fixed in the previous section. The smallest value for c, is b + 1, so if we substitute this into the above, we get:

 

1000 – a = b + (b + 1)      therefore            1000 – a = 2b + 1             therefore            (999-a)/2 = b

 

So b can be expressed as:

 

a < b <= (999-a)/2

 

 

The final step is to calculate c. Thankfully this is quite easy with the values of a and b already assigned as c = 1000 – a – b. Now that we have all this prepped, we can begin the question.

 

 

Method:


1) Generate rows of data, for all the possible values of a, as calculated above. (i.e 100 <= a <= 332).

Pilsner_2-1759100489675.png

 

 

 

2) Generate, rows of data, for all the possible values of b, as calculated above. (i.e a < b <= (999-a)/2)

 

 

Pilsner_3-1759100519361.png

 

 

 


3) Calculate c (1000 - a – b = c)

Pilsner_4-1759100565449.png

 

 

 

4) Filter to records with a pythagorian triplet.

Pilsner_5-1759100585171.png

 

 

 

 

5) Find the product of a, b and c

Pilsner_7-1759100623901.png

 

 

 

 

6) Submit your answer to the Project Euler Website!

 

BenjamminsTakeChargeGIF.gif

 

 

 

 



Summary:

Like last week, this approach doesn’t have a simple formular that just gives you the answer, but considering we limited a potential 1 billion rows down to ~ 40 thousnd, I hope the power of setting bounds can be seen.

Want to find out more, follow this link to our introduction post - Euleryx: Let The Games Begin.

 

12 REPLIES 12
patrick_digan
17 - Castor
17 - Castor
Spoiler
image.png
Hub119
12 - Quasar
12 - Quasar

Almost caught up...

Spoiler
PE-9.png
NicoleJ
Alteryx
Alteryx

Solved in Designer Cloud - Definitely would have to think through some ways to better limit the B values generated if I was doing this with a larger number than 1000, but brute force worked for this one with just limiting the values for A...

Spoiler
Euleryx9_DC.png

Cheers!
NJ
Director, Product Management
Alteryx
Labels
Top Solution Authors