Want to get involved? We're always looking for ideas and content for Weekly Challenges.
SUBMIT YOUR IDEAVery interesting challenge - I'm sure everyone went about it in a different way. Here's mine:
I calculated the root of the input number, 50, to get the list of integers to use for testing - 2 to 7. I created the list of numbers to be tested, 2 to 50. I excluded the single-integer prime numbers for simplicity. For the others, I checked which ones have a remainder when divided by one of the numbers between 2 and 7. I joined the two lists for a full list of integer numbers between 2 and 50.
One step includes removing numbers equals to the dividends, this makes the workflow usable for very large numbers as well. It's still quite fast with numbers in the thousands 🙂
A fun challenge for sure! Great to approach these fundamental concepts through the lense of Alteryx.
Good challenge. Here's an iterative macro implementation of the Sieve of Eratosthenes. The trade off is speed vs memory use by not requiring the X join at the start that the divisor method requires. The table is never bigger that N-1 rows but gets iterated over once for every prime less than SQRT(N)
Dan
Hi!
I tried to minimize the number of checks.
As there is only 1 odd prime, which is 2, I decreased the generate rows by the following loop expression:
if Number < 3 then Number + 1 else Number+ 2 endif.
Further the range which we need to check if a division can be made starts with 3
(no uneven number can be divided by 2, and is maximized on 1/3 * [number].
So as you can see in the workflow, it works quite fast.
But even then finding all the primes under 25000 generates around 26 mio checks!
Fun challenge! Definitely curious to see how others did this as I don't think my solution is the most efficient.