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 20 – Factorial Digit Sum

Pilsner
13 - Pulsar

Euleryx Problem 20 – Factorial Digit Sum

Pilsner_8-1767296967395.png

 

 

My workflow and macro:

 

Spoiler

Workflow:

Pilsner_9-1767296981725.png

 



Macro:

Pilsner_10-1767296986603.png

 

 

Answer: 648



 

Last Week's Favourite Solution:

The favourite solution award for problem 19 has to go to @DaisukeTsuchiya. With two solutions, one utilising Alteryx’s built-in functions and the other solving the problem using basic numeric values alone, this solution is well worth a look. Please find their solutions on page one of last week's post or click here.

 

Mathematical Theory:

This problem is in many ways similar to Project 16, as we have to multiply large numbers together. As we already know, computers struggle to do direct mathematical calculations of larger numbers. A way to get around this is to break the numbers into their single-digit components.

ItalianNightmareWebpacGIF.gif



Lets take a small number (99) as an example:


We already know that 2 x 99 is equal to 198. But do we actually calculate this? A common trick taught in school is to multiply the digits separately, and then add all the answers together. I.e do 9 x 2 and then 90 x 2 as two separate calculations.

Pilsner_7-1767296873945.png

 

 

This same principle works with larger numbers. As the computer cannot handle large numbers by itself, we will just break them up into separate digits.

 

Method:

1) The first step is to simply create your starting value. I decided to perform the multiplication by increasing the value each time, i.e 1 x 2 x 3 x …. x 100, hence the input value is 1.

 

Pilsner_6-1767296868180.png

 

2) Next, we enter the iterative macro (for illustrative purposes, I have the number 99 flowing through the macro). Inside the iterative macro, the first steps, is to add some placeholder rows.

Pilsner_5-1767296803624.png

 

 

The placeholder rows should appear at the bottom. Writing this number out normally, we should get 0099, which is just 99. The purpose of the placeholders will become clear shortly.

 

3) Now we perform the multiplication based on the engine iteration number. In this case we are simulating the first iteration so the value 99 with be multiplied by 2.

Pilsner_4-1767296794321.png

 

You will notice that the “New number” column, looks a little different. The value in this column is formatted so you have the units_non-units.

- So for the first row, 9 x 2 is 18, it’s the first row, hence we don’t need to worry about anything else. We then write the answer 18, in the units_non-units form to get 8_1

  • For the second row. 9 x 2 is also 18, but on the previous row, there is also a 1, in the “non-units” section, so we have to add this onto our calculation: 18 + 1 = 19. Expressing this in the same form, we get 9_1
  •  The third row is actually one of the placeholders, hence the multiplication 0 x 2 = 0. But again, as we have a 1 in the non-units above, we need to add that value on, to get 1_0.
  • The final row is just 0

 

4) Now we can simply take the units values, and paste them into the original “input” column.

 

Pilsner_3-1767296758383.png

 

Reading the value out, we would get 0198 = 198. We can then also drop the “New Number” column.

 

5) The final step within the macro is to decide whether to loop again or not. This is determined by a filter on the engine iteration number, powered by a numeric up-down, on the macro interface. For the purpose of this problem, it has been set to 100.

 

 

Pilsner_2-1767296749239.png

 

6) Once the macro has ran, the value of 100!  will be expressed in a single column, each cell containing a single digit only.

 

Pilsner_1-1767296744704.png

 

To express the number ordinarily, you could reverse the order then concatenate the values; however, as this column format displays all the digits individually, to answer this problem, we can simply sum the column to get to the answer.

Pilsner_0-1767296721122.png

 

 

7) Submit your answer to the Project Euler Website! 

GifGIF.gif



Summary:

Another problem to test how well we handle large numbers, but like before, we were able to arrive at an answer by isolating the digits, converting the large number calculations into lots of small multiplications and additions.

 

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

 

1 REPLY 1
Hub119
12 - Quasar
12 - Quasar

Keeping with the theme of some of the previous problems, I decided to continue along the path of making my inputs built to store a single digit of the overall number as individual records... this way while my record count may expand, it shouldn't get too out of control and I don't risk Alteryx not being able to handle the size of the number when it goes beyond Int64...

Spoiler
Workflow/Input ConfigWorkflow/Input Config
Spoiler
I decided to start with the overall number for my factorial multiplication and then count down to 1 at which point I would exit the iterative loop.
Factorial MacroFactorial Macro
Labels
Top Solution Authors