Start Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Euleryx Project 16 – Power Digit Sum

Pilsner
13 - Pulsar

Euleryx Problem 16 – Power Digit Sum

Pilsner_0-1763038681000.png

 

My workflow and macro:

Spoiler

 

Workflow:

Pilsner_3-1763038720191.png

 


 



Macro:

Pilsner_2-1763038707836.png

 



Answer: 1366



Last Week's Favourite Solution:

Last week saw some very different approaches. Whilst I would like to give a shout out to @patrick_digan for the commitment to the macro-less brute force method, @DaisukeTsuchiya  has won the favourite solution award. In this solution, you will see several different macros built to calculate the multiplication or division of numbers using string values instead of numeric, meaning it should work for numbers of any size. (You might even find some of the techniques @DaisukeTsuchiya  used in my solution to this week's problem). Please find their solutions on page one of last week's post or click here.

 

 

Definitions:

  • Power: The power of a number is the result of multiplying said number by itself a set number of times. I.e 2 to the power of 3, is 2 x 2 x 2 = 8

Mathematical Theory:

This week's challenge can be quickly optimised by using one of the exponent laws, commonly referred to as the Power of a Power rule.

 

BunniesWhatGIF.gif



The “Power of a Power” rule states that we can rewrite the power of a number as follows:

 

Pilsner_2-1763053250972.png



What this is telling us is that if we have a number “a” multiplied by itself “n” times, which is then multiplied by itself “m” times, it’s the same as just doing to the original number “a” multiplied by itself (n x m) times. So if we had two to the power of 2 all to the power of 3, we could rewrite this as follows:

Pilsner_1-1763053165614.png



Intuitively, this works well too because if we write out both sides of the equation in full, we get:

 

Pilsner_3-1763053280373.png

 

 

However, for this particular problem, we don’t have an “n” and an “m” value; we just have 2 to the power of 1000.

CatGIF.gif

 

 

The trick here is to look at things the other way around. As we know:

Pilsner_4-1763053311521.png

 



We therefore also know that:

Pilsner_5-1763053332430.png

 



The beauty of looking at things this way round means that not only can we now start with 2 to the power of 1000, but we can also choose our own values for n and m.

 

Two to the power of 1000 is a very large number; therefore cannot just be calculated using the Pow() function, as it exceeds the numerical limit in Alteryx. Instead, we are going to have to use string values to help us calculate things one digit at a time.

 

Now -  slight spoiler alert - I used an iterative macro to solve this week's problem, so ideally I want to minimise the number of iterations. I'm also conscious that I cannot exceed the maximum integer value (int64), so I decided to set n = 40 and m = 25 (as 25 x 40 = 1000).

 

Pilsner_6-1763053446512.png

 

 

This means that instead of doing 1000 iterations where I multiply by two each time, I can do just 25 iterations, and multiply by 1099511627776 (2 to the power of 40) each time.

Method:

1) Create an input (although this will actually be overwritten shortly).

Pilsner_4-1763038946829.png

 


2) Implement the optimisation we mentioned above and update the starting value and Power accordingly:

Pilsner_5-1763038960026.png



3) Update the column called “Number” to be a string, and feed the data into the Power Macro.


Pilsner_6-1763038969646.png

 



a) Begin by reversing the string and parsing it out so we have one digit per line:

Pilsner_7-1763038993272.png

 

 


b) Multiply each digit by the starting value:

Pilsner_8-1763039000732.png

 

 

 

c) Now implement a multirow. We effectively need to add the row above, onto the current row. However, don’t forget that each row is out by a factor of 10 when compared with the row above, hence we need to ignore the units (I did this by dividing by 10 and using the floor function).

Pilsner_9-1763039008725.png

 



d) It's important to know which row is the final one, hence I used the summarise tool and append to help with this.

Pilsner_10-1763039015368.png

 



 

e) For all rows except the last one, we only care about the end digit, as all other digits were added to the line below. Hence, we use a formula tool to remove the unwanted values.


We have also updated the Power column, as each iteration is a single multiplication, hence reducing the remaining required multiplications by 1.

 

Pilsner_12-1763039034397.png

 



f) Finally, I sorted the Record ID in descending order and concatenated the string. If the remaining power is 1, we have finished; therefore can exit the loop, otherwise we require another iteration.

Pilsner_13-1763039042550.png

 



4) Back outside the macro, I parse the digits so we have one per record:

Pilsner_14-1763039050491.png

 


5) Finally, the digits are summed using the summarise tool to get to the final answer.

 

Pilsner_16-1763039082192.png

 

 


6) Submit your answer to the Project Euler Website!

TaDaHouseMdGIF.gif

 



Summary:

 The Power of a Power rule was not able to help us arrive at an immediate solution; however, it did reduce the required iterations from 1000, down to just 25. With a 97.5% reduction of iterations, it proved to be a valuable tool in a very large number problem.

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

9 REPLIES 9
Hub119
11 - Bolide
11 - Bolide

Implemented a macro for this one, treating each digit as an individual record... then just need to sum the digits at the end.

Spoiler
WorkflowWorkflow
Spoiler
Power MacroPower Macro
Pilsner
13 - Pulsar

I like the addition of the numeric up-down for setting the exponent part in the macro!

Hub119
11 - Bolide
11 - Bolide

Have to be prepared in case I need to use this again... part of the whole build it once, use it over and over Alteryx idea, right? 😉

Pilsner
13 - Pulsar

Very true indeed - wise words😄

Qiu
21 - Polaris
21 - Polaris

I will go with the approach that turning addition to string addition, similar with @Hub119 maybe.

since basically 2xA = A +A.

Spoiler
Euleryx Project 16A.jpgEuleryx Project 16B.jpg
WirkKarl
8 - Asteroid

Cool to see how different the approaches were last week — especially the macro-less brute force attempt. But yeah, Daisuke’s solution really deserved the highlight. Using string-based multiplication/division to bypass numeric limits was super clever, and honestly something I might borrow for a couple of my own workflows.

We use a similar idea in parts of our data pipelines at Phonexa when dealing with oversized numeric values coming from external sources, so seeing it applied in Alteryx like this was great.

PangHC
13 - Pulsar

built BigInt product macro to multiply by digit and group.
So generate 1000 rows of 2. 

I process the multiply by pairs. hence 1000 rows will be 10 iteration where (2^10 = 1024).

Spoiler
PangHC_0-1763349219840.png

 

DaisukeTsuchiya
14 - Magnetar
14 - Magnetar

@Pilsner  @WirkKarl 

Thanks so much for the great feedback on my WF! I'm thrilled to hear you liked it.

I really struggled to build that multiplication and division macro to handle huge numbers, but I pushed through to get it done for the Euleryx problems after #50.

For this week's problem, I just had to tweak the macro from last week a bit to get it working.



Spoiler
I customized WF used for #15.
=============<Comment for #15 >===========================
Many of the Project Euler problems, especially from around #50, involve calculations that exceed the limits of INT64.
I actually built this workflow in the weekend to tackle such issues to solve the combinatorics problem in #53, where some intermediate values grew to over 150 digits long. So, I figured I might as well use it here too.
========================================================

スクリーンショット 2025-11-19 213847.jpgスクリーンショット 2025-11-19 213916.jpg

 

AkimasaKajitani
17 - Castor
17 - Castor

My solution!

 

Spoiler
Basically, I multiplied 1000 times by iterative macro. However, I ensure the digits in advance and I have the digits in row, so as a result my macro becomes very simple.

AkimasaKajitani_0-1763776984961.png

AkimasaKajitani_1-1763776999238.png

 

 

Labels
Top Solution Authors