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

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 

Alteryx
Alteryx

catching up.

Asteroid

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

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

 

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

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.

Meteoroid

Yet another solution

Asteroid

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

Asteroid

My solution:

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