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 #79: Find the Closest Prime Number

Highlighted
8 - Asteroid
Welcome to the Weekly Challenge. Each week Alteryx post a use case where you can put your Alteryx skills to the test. You'll be able to share your answers an...
Highlighted
Alteryx Partner

Here's my solution

 

Spoiler
Simonvm9114_0-1581947259683.png

 

Highlighted
Alteryx Partner

I really enjoyed this challenge. The "mathy" ones are always fun for me.

 

There are three potential cases here:

  1. The given number is prime → outputs the same number.
  2. The closest primes above and below the number are different distances from the number → output the closest.
  3. The closest primes above and below the number are the same distance from the number → concatenate both into a comma-separated list.
Spoiler
Like most others, I built an iterative macro. It starts at the given number and counts one step up and down per iteration, checking each new value for primality. This could certainly be made much more efficient by paying attention to the parity of the given number, storing previously known primes from prior iterations, and so on.

Macro Capture.PNGSolution Capture.PNG
8 - Asteroid

Thanks JoeM.

Highlighted
8 - Asteroid

Check out my solution!

It has one constraint that I only check numbers up 10000

And it allows to output more than one closest prime number to the input in case the difference between previous/ next Prime and Input is the same. 

Highlighted
8 - Asteroid

On a spree to binge complete weekly challenges
Adrenaline rush

 

I solved it using python tool

atcodedog05_0-1585475887060.png

 

Spoiler
This is my solution
atcodedog05_0-1585475749604.png

 

Check the workflow flow for the python code