Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Weekly Challenges

Solve the challenge, share your solution and summit the ranks of our Community!

Also available in | Français | Português | Español | 日本語
IDEAS WANTED

Want to get involved? We're always looking for ideas and content for Weekly Challenges.

SUBMIT YOUR IDEA

Challenge #187: Generate Prime Numbers

JohnJPS
15 - Aurora
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
T_Willins
14 - Magnetar
14 - Magnetar

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

 

Spoiler
Iterative MacroIterative Macro

 

MacroMacro

 

WorkflowWorkflow

 

TonyA
Alteryx Alumni (Retired)

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??
JORGE4900
8 - 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
TylerNa
10 - Fireball

Optimus prime would be so proud...

Prime Numbers.jpg

Spoiler
WC 187 Prime Numbers TN.png
paulfound
11 - Bolide

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? 🙂 

patrick_digan
17 - Castor
17 - Castor

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
hbraunius
8 - Asteroid

My solution attached.

justindavis
10 - Fireball
Spoiler
challenge_187_solution_justindavis.PNG
Adam_Dooley
8 - 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