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 4 - Largest Palindrome Product

Pilsner
13 - Pulsar

 

Euleryx Problem 4 - Largest Palindrome Product

  

Picture1.png

 

My workflow and answer:

Spoiler
2.png


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:

  • Product: The result of multiplying two numbers together.
  • Palindrome: A number (or word/ sequence) which reads the same backwards as  it does forwards. E.g. 101.

 

Weighing up the options:

 

Two main routes sprang to mind here:

  • Use an iterative macro. This would allow us to stop calculations as soon as the answer is found.
  • Use generate rows to find all possible palindromes, then take the greatest.

 

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! 

 

DaddysHome2DaddysHome2gifsGIF.gif

 

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:

 

  1. To begin with, I used a generate rows to create my input values. Instead of generating all numbers from 0-1000, I instead only generated the 3-digit numbers by starting from 100 and ending at 999.
    Picture3.png



  2. Next, I appended this list to itself to create all combinations of 2, 3-digit numbers.
    Picture4.png

      




  3. Here’s where we can save some time, as we are finding the product, the order of the numbers does not matter, i.e. 100 * 200 = 200 * 100, therefore considering  both records would be redundant.

    This will occur with almost every pair of 3-digit numbers. To remove these redundancies, we can use a filter to state that the number in the left-hand column must be greater than (or equal to) the number in the right-hand column. This leaves us with only 405,450 records going forward.

    Picture5.png

  4. Calculate the product of all the 3-digit number pairs. And reverse the answer, too.
    Picture6.png

  5. Filter to records, where the product = the reversed string. Then sort and sample to get the greatest value.
      Picture7.png


  6. Submit your answer to the Project Euler website

FinishedImSoDoneGIF.gif



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.

 

15 REPLIES 15
Qiu
21 - Polaris
21 - Polaris

Also very straightforward.

Spoiler
Euleryx Project 4.jpg
patrick_digan
17 - Castor
17 - Castor
Spoiler
image.png
TheOC
16 - Nebula
16 - Nebula

Simple enough challenge. I fear I'm being coerced into a false sense of security and Euleryx is going to rip that away soon with much more difficult challenges...

 

Spoiler
TheOC_0-1756300867136.png


I basically created all sums, used a right and a left string function on the product, and then filtered / took the highest!

Cheers,
TheOC
Connect with me:
LinkedIn Bulien
Pilsner
13 - Pulsar

I've been looking forward to reading these, there are some great solutions! 

@gawa , that was a very clever assumption. It took me a moment to get my head around your idea, but I like it a lot! 

I never would have thought to start with the palindromic numbers,  @Yoshiro_Fujimori. I have checked, and I believe your answer was correct for 4-digit numbers, too. This is such an efficient solution.

AkimasaKajitani
17 - Castor
17 - Castor

My solution!

 

Spoiler
image.png
CoG
14 - Magnetar

Simple Brute Force, but nice 3 Tool solution. I was trying a different approach, so my Generate Rows Tool is inefficient

 

Spoiler
Screenshot 0004-1.png

Fun problem!

 

 

Labels
Top Solution Authors