Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!
New content is available in Academy! You may need to clear your browser cache for an optimal viewing experience

Challenge #187: Generate Prime Numbers

Highlighted
Alteryx Certified Partner

A prime example of a good weekly challenge.

 

In one line of Python,

[i for i in range(2,50) if 0 not in (i%j for j in range(2,i))]

 

Otherwise,

Spoiler
WorkflowWorkflow

CodeCode

 

 

Highlighted
Atom

Here's my solution

 

Spoiler
187 sol.PNG
Highlighted
Meteor

This solution is very inefficient and generates a lot of waste data:

 

 

Spoiler
Capture.PNG
Highlighted
ACE Emeritus
ACE Emeritus

@elliotyoung - I used the R tool here.

Highlighted
Fireball

No pretty, but I got there. 

 

solution attached. 

Asteroid

I liked this one!

 

Spoiler
image.png
Highlighted
Alteryx Partner

A good old sieve. 998 iterations in ~1 min for primes under 1 000 000 all in Alteryx

Spoiler
1. Main Workflow generates the rows and feeds the iterative macro, then filter primes1. Main Workflow generates the rows and feeds the iterative macro, then filter primes2. Loop through the integers that are still prime until SQRT(Target) and flag whether number is divisible (discard) or not (keep)2. Loop through the integers that are still prime until SQRT(Target) and flag whether number is divisible (discard) or not (keep)
Highlighted
Asteroid
 
Highlighted
Alteryx
Alteryx

Think my solution may be a little too simplistic, but it gets the job done! 2 tools.

 

echuong1_0-1572964644531.png

Highlighted
Alteryx Partner

Here's my solution, it is based on trial division method. For very large numbers it will be slow to generate the data required but it will work.

 

Spoiler
Alexandru_Bostan_0-1573037425616.png