Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Some Alteryx fun - the King's quest

ulrich_schumann
8 - Asteroid

My son came from school today with a math challenge. I saw (and think understood) the mathematical solution. So I thought, this could be also possibly solved within Alteryx.

 

So here is the challenge:

It is the birthday of the king and therefore he will release some prisoners. The king has 1000 prisoners, everyone in a single cell.

 

He advised his guard to:

- go 1000 times along the cells

- in the first round the guard has to go to every cell, in the second round to every second cell, in the third round to every third cell and so on

- every time the guard comes to a cell, he has to turn the key (so lock or unlock the door)

- at the start all cells were locked

 

How many prisoners will be released after 1000 rounds?

 

Any ideas? - Have fun!

10 REPLIES 10
JohnJPS
15 - Aurora

I was writing this up a little since it led me to a really nice discussion of problem solving and thinking outside the box. In all (for me) I looked at four solutions:

  • (1) My original workflow was very complicated with numerous tools, but did the job, and since it went through all they gyrations, it was cool to literally see a grid of lock-togglings... also we could observe that the "unlocked locks" were all the perfect squares.  Since the solution was cumbersome to maintain, slow and memory intensive, the "perfect squares" insight led to a tremendous simplification:
  • (2) Just check whether or not each number was a perfect square.  However, even that is somewhat computationally intensive, checking SqRt vs Floor(SqRt) for every number, 1 to [n].... so another equally tremendous simplification was to:
  • (3) Just generate a list of perfect squares smaller than [n]; this loops only SqRt([n]) times without even needing to calculate a SqRt, and only does one multiplication per instance of the loop... but finally, we can take it even a step further: how many perfect squares are there between 1 and [n]?
  • (4) Obviously, there are just Floor(SqRt([n])).  So that's all we need: a single formula expression that accepts [n] and spits out the answer in a flash.

Performance-wise... for n = 10,000, my computer was already choking on the first solution; for n=10,000,000, it was bogging down on the second... for n=1,000,000,000,000,000, the third generative solution was up to about 7 seconds... still quick, but the final solution was still just a half second. If you have big data or need to iteratively make complex calculations numerous times, then these kinds of exercises - looking for these kinds of insights - can yield incredible dividends. Discerning insight into our solution took a rather difficult problem (unassailable for large [n]) into something that can be delivered almost instantly.

 

I'm sure the fast solution was obvious to some right away... for me it was a valuable lesson. thanks for the challenge!

Labels
Top Solution Authors