# Weekly Challenge

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

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback
We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

## Challenge #187: Generate Prime Numbers

Highlighted
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.
Highlighted
13 - Pulsar

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

Spoiler
Iterative Macro

Macro

Workflow

Highlighted
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??
Highlighted
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
Highlighted
9 - Comet

Optimus prime would be so proud...

Spoiler
Highlighted
8 - Asteroid

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

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?

Highlighted
16 - Nebula

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.

Highlighted
8 - Asteroid

My solution attached.

Highlighted
8 - Asteroid
Spoiler
Highlighted
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