Let’s talk Alteryx Copilot. Join the live AMA event to connect with the Alteryx team, ask questions, and hear how others are exploring what Copilot can do. Have Copilot questions? Ask here!
Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 5 - Smallest Multiple

Pilsner
13 - Pulsar

Euleryx Problem 5 - Smallest Multiple

q.png

 

My workflow and answer:

Spoiler

Pilsner_0-1756384534094.png

Answer: 232792560

 


Last Weeks Favourite Solution:
There are already some very clever solutions to last weeks challenges, they have highlighted how sometimes making an educated assumption can drastically reduce to workload. This week, our favourite solution award goes to @Yoshiro_Fujimori. By flipping the problem on its head, and creating a descending list of palindromic numbers as the starting point, @Yoshiro_Fujimori's solution was incredibly efficient and even found the answer to the problem with 4 digit numbers. Find this solution on page 1 of last week post, or click here.

 

Definitions:

  • Evenly Divisible: Despite the misleading name, this does not mean divisible by an even number. What this actually means is, divisible without a remainder or decimal.

 

Mathematical Theory:

 

This problem is effectively asking us to find the Lowest Common Multiple (LCM) of all the numbers 1-20. With this in mind, we can use a method often referred to as the LCM by prime factorisation. So, what does this mean?  

 

Let's begin with the prime factorisation part. As we have seen before (in Problem 3), the Fundamental Theorem of Arithmetic states that all numbers can be factorised into prime numbers. We also saw how to do this using a factor tree.

 

Pilsner_1-1756384534172.png

 

 

From this point forward, we will use the numbers 30 and 28 as examples and for those who have forgotten, here are some factor trees and the prime factors for these numbers.



Pilsner_13-1756384908607.png


Prime factors 30 = 2 x 3 x 5

Prime factors 28 = 2 x 2 x 7

 

Now that we have the prime factors, we can use them to find the LCM. The rule here is to take the highest power, of each prime and multiply them all together. So, in this example:

 

  • 30 = 2 x 3 x 5
  • 28 = 2 x 2  x 7

The unique prime numbers here are 2, 3, 5 and 7. Let's find the highest power for them all:

  • For 2: 2 x 2
  • For 3: 3
  • For 5: 5
  • For 7: 7



Or if you want to do this pictographically, use a Venn diagram:

Pilsner_4-1756384534174.png

 

 

By taking this list of numbers (either from the Venn diagram or the list of highest powers) we come up with the following expression:

 

2 x 2 x 3 x 5 x 7 = 420

 

Therefore, the LCM of 30 and 28 is 420.

 

 

Applying this method to the problem at hand, if we find all the prime factors of the numbers from 1 – 20, then create a list of each one's highest power, we should arrive at a solution.

 

 

Method:

 

As hinted at above, this method leverages the iterative macro created for Problem 3. For this problem, I will just refer to it as the List of Prime Factors macro, but if you want a more detailed explanation, please look back at Problem 3.


  1. This process begins with generating our data (numbers 1 – 20) and setting up some columns ready for our iterative macro. In this case we need out starting number to be static, a column which can be populated with our list of primes, and another Number column to update each iteration.
    Pilsner_5-1756384534175.png
  2. Feed the input into the List of Prime factors macro to get the following output.

    Pilsner_6-1756384534176.png
  3. We need to figure out the power of each prime factor, per starting number. The first step here would be to separate out the list of prime factors into separate rows, based on the comma delimiter.
    Pilsner_7-1756384534176.png

  4. Count the number of times each prime number appears as a prime factor, per starting number. (This is effectively finding the power of each prime factor).

    Pilsner_8-1756384534177.png

  5. For each prime number, find its highest power. (Remember count = power)
    Pilsner_9-1756384534178.png

  6. Calculate the value of each prime when its highest power is applied.
    Pilsner_10-1756384534179.png

  7. Multiply all the values you have just calculated together to get your answer.

    Pilsner_11-1756384534181.png

  8. Upload your answer to the Project Euler Website!
    CheckedOutGIF.gif

 

Summary:

Although the question didn’t explicitly state this, the trick we used was to recognise that it was asking for the Lowest Common Multiple. Armed with this idea, we were once again able to utilise the Fundamental Theorem of Arithmetic to find to LCM via prime factorisation.

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

11 REPLIES 11
CoG
14 - Magnetar

Great Math Principles involved, and still string coding in Generate Rows Tool!

 

Spoiler
The key approach is Euclid's algorithm to calculate the Greatest Common Denominator:
If a < b, then GCD( a , b ) = GCD( mod( b , a ) , a )

coupled with the fact that LCM( a , b ) = a * b / GCD( a , b ),

we can solve this problem very efficiently!

Screenshot 0005-1.pngScreenshot 0005-2.png

 

 

Carolyn
12 - Quasar
12 - Quasar

@CoG - You're going to present on this at next Inspire, right??

Labels
Top Solution Authors