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

arjanloogman
8 - Asteroid

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 

nitinsnow
Alteryx Alumni (Retired)

catching up.

Carlithian
11 - Bolide
11 - Bolide

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

jgomel
7 - Meteor

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

 

Ruud
10 - Fireball
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 😄

lcrosby
7 - Meteor

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.

Galouzis
7 - Meteor

Yet another solution

ADerbak
11 - Bolide

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

nini
8 - Asteroid

My solution:

jgomel
7 - Meteor

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