Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Community is experiencing an influx of spam. As we work toward a solution, please use the 'Notify Moderator' option on the ellipsis menu to flag inappropriate posts.
Free Trial

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

JacobR77
8 - Asteroid

Good challenge!

 

Mine slows down as the numbers entered gets higher, but works. Probably a more elegant solution that I'll look into now.

mceleavey
17 - Castor
17 - Castor

Oooooh, I liked this one. Iterative macros ahoy!

 

Spoiler
Ok, so I started with creating the maths behind a prime number identifier. I used a generate rows tool using RowCount <= sqrt([Number]) as the expression, beginning at 1 and looping by +1. Effectively this creates every factor between 1 and the square root of the number.
In the example of 100, this creates rows between 1 and 10.
Dividing 100 by each of these numbers and you are presented with decimal numbers and/or factors. I then split the resulting column by the decimal point and counted the instances of a null in the second column. This counts the numbers of results without a decimal place, ie a full number. this represents a number by which the original number is divisible.
Once I had determined if the number was prime, I changed the workflow to be an iterative macro, built in an iterative formula on the number and placed a filter on the field that determines if the number is prime. On the true output I placed a macro output which represents the end of the iteration, that is when the answer is Y, and on the false output I joined by to the input to form the iterative loop.
This is my iterative macro, "Prime". I then copied this, replaced the iterative + with iterative - to run down from the number and saved this as "Prime2": Macro.PNG

Iterative Macro.PNG

I then built an analytic app to allow the user to select the number and an HTML output to view the results. 
This will show the closest, next and previous prime number for any number selected (up to 100,000,000).

Workflow.PNG

results.PNG




Bulien

CHarrison
8 - Asteroid

My favourite one so far! A true head scratcher ;)

 

Used my knowledge of mathematics & macros to get this one! 

data_rachel
8 - Asteroid

Duplicate post

data_rachel
8 - Asteroid
Spoiler
I ended up with two slightly different macros running in parallel to get the higher/lower prime on either side of the input number n.

challenge79.PNG

This was a good recap of iterative macros. I enjoyed this challenge so much I extended it and then wrote a blog post about it! https://vizteriousgirl.wordpress.com/2018/04/03/prime-numbers-1/ 

danilang
19 - Altair
19 - Altair

Nice Challenge.  My first iterative macro.  Tricksy beasts.  It's the first time where I've found that disabling Unknown field pass through is actually useful.

 

Tip 'o the hat to @MarqueeCrew for the idea of bracketing the starting number and searching from there

 

 

Spoiler
Solution consists of the app and 2 nested Macros.  The innermost one (IsPrime) checks to see if a number is prime using the sieve approach.  Two optimizations here
1.  if the number is even, it by passes the sieve completely
2.  the sieve itself only needs odd divisors since the number is guaranteed to be odd by #1

IsPrime.png

The outer macro(ClosestPrimeFinder) iterates through the numbers larger and small than the input, calling IsPrime until a prime is found

ClosestPrimeFinder.png

The App checks if the input is prime first and if not passes the input number to ClosestPrimeFinder.  

Solution 79.png

Dan

 

 

kat
12 - Quasar

One of my favorite challenges!

Spoiler

Challenge #79.PNG
Challenge #79 macro2.PNGChallenge #79 macro1.PNG
JoBen
11 - Bolide

Cheers!

dsmdavid
11 - Bolide

 

That was quite fun

 

Spoiler
App with nested macros
Main App - tests whether the number provided itself is prime or not, and calls iterative macro to find closest primeMain App - tests whether the number provided itself is prime or not, and calls iterative macro to find closest primeIncrease/Decrease values to get closestIncrease/Decrease values to get closestis odd / evenis odd / evenis the number divisible by any odd number < sqrt?is the number divisible by any odd number < sqrt?
2

 

AndyBate
8 - Asteroid

complete