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
Alteryx Partner

This one was fun and fast!! Didn't have to peek or google on this one, adds to my confidence...

 

Spoiler
Screenshot 2019-10-31 at 09.59.17.png

Regards,

 

Arjan Loogman 

Highlighted
Alteryx
Alteryx

catching up.

Highlighted
8 - Asteroid

A fun challenge that I used to teach someone how to make iterative macros This is what we came up with

Highlighted
6 - Meteoroid

Here's my solution which allows you to set up what maximum value you want to find prime numbers for (limited to 10k, but can be increased)

I essentially use an iterative macro within a macro. Solution below.

 

Spoiler
Start doesn't look like much, you just simply change the input to the maximum number you want.

jgomel_1-1572518688142.png

The macro will then just generate all the numbers excluding 1 and send to the iterative macro
jgomel_2-1572518748581.png

In the iterative macro the values will be looped through removing along the way the values that could be divided by the smallest integer availalbe.
The exception being when the integer and the lowest integer are the same, which are the prime numbers. Et Voila!
jgomel_3-1572518799289.png

 

Highlighted
Alteryx Certified Partner
Spoiler
Capture2.PNG

Capture.PNG

Decided I make it slighty more efficient by skipping all even numbers and appending only numbers that are smaller than my starting number. Batched it on number and was good to go. Still super brute-force

Highlighted
6 - Meteoroid

Nice simply idea to remove even numbers - I amended my solution to do the same (which doesn't use a macro and doesn't just compare smaller numbers) and it reduced the run time from 55 seconds to just under 10.

Highlighted
6 - Meteoroid

Yet another solution

Highlighted
9 - Comet

I liked this one a lot! Didn't even use the input or an input tool

Highlighted
8 - Asteroid

My solution:

Highlighted
6 - Meteoroid

Second solution posted, but optimized using an Iterative macro. The flow initial value can be updated to find more or less primary numbers.

 

 

Spoiler
jgomel_1-1572536256715.png

Iterative macro details

jgomel_2-1572536324361.png