Euleryx Problem 4 - Largest Palindrome Product
My workflow and answer:
Answer: 906609
Last Weeks Favourite Solution:
Last week's episode had some really interesting discussions, thank you everyone for being so detailed in your answers. This week, we have selected @patrick_digan's solution as our winner! We loved the idea that you could calculate which factors were prime by simply checking if they were divisibly by the other factors. If you want to check out @patrick_digan's post, find it on page two of last weeks challenge, or click here.
You may also have noticed that we have been recognised with an official "Project Euler" label, now attached to all of our posts. Thanks for the amazing feedback and support all, shout out @Carolyn for being the Euleryx mascot!
Definitions:
Weighing up the options:
Two main routes sprang to mind here:
On the face of it, an iterative approach sounds like the quicker option as it involves fewer calculations; however, if the Advent of Code has taught me anything, it's to properly consider all options. If not, you may pay the price with a lengthy run time!
If we went the generate rows route, we would need to calculate the product of every 3-digit number pair. As a rough estimate, this would be 1000 * 1000 calculations (1,000,000). Whilst this seems like a large number, this is not a great deal of records for Alteryx, so I decided to go with this method. (Plus, I had a couple of ideas in mind to significantly reduce this number.)
Method:
Summary:
Whilst the solution this time was somewhat brute force; we were still able to use a couple of tricks to reduce the computation required.
Want to find out more, follow this link to our introduction post - Euleryx: Let The Games Begin.
Solved it straightforwardly.
Did it!
Haha omg @DaisukeTsuchiya same solution!! You beat me to it.
Many ways to solve this, and the main difference being Number vs String for the palindrome check...
Solved!
Initially I did a Generate Rows with all the numbers from 900 to 999.
But then for v2, I thought about how since we're talking about products, I know that my numbers will end in either 1, 3, or 9, assuming that my palindrome product starts with 9. So then I redid my Generate Rows and instead of 1000 values, I only had 30.
And I agree with others - ReverseString is such a fun function that I don't often get to break out!
I implemented a pruning with fuzzy assumption 'answer would be 6 digits'. With this, I just had to examine the number of multiple of 11. More in spoiler.
My solution.
I also tried with 4-digits numbers.
Workflow
1. Generated rows with column [a] from 999 to 900.
(assuming there would be at least one Palindromic number)
2. Calculate Palindromic numbers [b] for each [a].
3. Generate rows for each row with new column [c] from Sqrt([b]) up to 999.
(Because one of the factor has to be smaller than Sqrt([b]).)
4. Check if [c] is a factor of [b].
Eventually, there was only one Palindromic number between 999999 and 900009.
Result: 993 * 913 = 906609