community
cancel
Showing results for 
Search instead for 
Did you mean: 
Do you have the skills to make it to the top? Subscribe to our weekly challenges. Try your best to solve the problem, share your solution, and see how others tackled the same problem. We share our answer too.
Weekly Challenge
Do you have the skills to make it to the top? Subscribe to our weekly challenges. Try your best to solve the problem, share your solution, and see how others tackled the same problem. We share our answer too.
Unable to display your progress at this time. Please try again a little later, or contact an administrator if you continue to see this error.
Getting started with Designer? | Start your journey with our new Learning Path!

Challenge #187: Generate Prime Numbers

ACE Emeritus
ACE Emeritus
Spoiler
I used an old prime factorization macro I wrote a while back.
It finds all prime factors so is a bit overkill; but was trivial to reuse here.
Macros are pretty quick: this does 1 - 50 instantly and 1 - 10,000 in just over a second...
But... results diminish: it takes ten minutes to do 1 - 1,000,000.
JohnJPS_2-1572280603240.png
Bolide

I reused most of the macros from Challenge #79, because recycling is good.

 

Spoiler
Iterative Macro 187.JPGIterative Macro

 

Macro 187.JPGMacro

 

Workflow 187.JPGWorkflow

 

Alteryx
Alteryx

Here's my solution. Not very different from the others. 

Spoiler
I did optimize it a bit by looking only at numbers that were multiples of two and only using divisors less than half of the number. This cut out the first few primes (2,3,5) so I added those manually. But this is still an n squared algorithm so with every 10x increase in the number of candidates, the time increases by 100x. It's actually worse than that because for larger data sets we have to start swapping to disk which kills the execution time. This runs in less than 7 seconds for numbers up to 10,000. I did find a paper that discussed an algorithm of order n. I may try to implement that in Alteryx when I have some time. Maybe in 2025??
Asteroid

I just upgrated to version 2019.3; I cannot wait to start using the Python interface to try this challenge. I remember doing this exercise for my Oracle database programming class.

Spoiler
2019-10-28_10-32-30.jpg
Comet

Optimus prime would be so proud...

Prime Numbers.jpg

Spoiler
WC 187 Prime Numbers TN.png
Meteor

Old favourite working out prime numbers. Up the number to 30,000 and got it ran in under a minute so that's good, won't break any records though.  

 

Spoiler

PaulFound_0-1572290733701.png

PaulFound_1-1572290778154.png


Looks like I could improve around the append to summary section, this is bottle neck

Has anyone got any suggestions on increasing the speed? Wonder how the new Alteryx Engine 2 would get on with this?  

I did a little workflow on prime numbers for our last Indianapolis User Group meeting! I made use of @jdunkerley79 's formula add ins

 

Spoiler
First I generate numbers to check. I start at 2, then 3,5,7,9 etc. Then I generate the list of divisors (>2 and <=Square root) and check that it's not divisible. Then I use the filter tool to get the primes and iterate my counter. The cool thing is that the counter from the filter tool actually feeds back into the generate rows tools and is the condition that stops it. This is possible with the VarNum and VarText functions that James created. They're so powerful! You will need to change my file from yxmd to yxwz.

Annotation 2019-10-28 154345.jpg
Asteroid

My solution attached.

Asteroid
Spoiler
challenge_187_solution_justindavis.PNG
Asteroid

Only used 5 tools (aside from the Expect Equal macro) so that's neat.  It helps that we only had to go to 50 or else this would get too manual.  

 

Spoiler
Capture2.PNG