Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

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 #406: What Is Your Lucky Number for the New Year?

AYXAcademy
Alteryx
Alteryx

Maveryx_WC_Banner.png

Hi Maveryx,

 

A solution to last week’s challenge can be found here. 

 

Roland van Leeuwen submitted this idea a while back, and now is the right time to share it! With 2024 approaching, let's determine our unique lucky numbers. Thanks, @RWvanLeeuwen, for your contributions to our Community!

 

In the quiet town of Serendipity Springs, there exists a magical tradition linked to Kaprekar's constant. Residents believe that the enchanted number 6174 holds the key to unlocking good fortune. This mystical connection is celebrated every New Year's Eve, adding an air of excitement and mystery to the festivities.

 

Following the rules of Kaprekar's constant, the townsfolk take their birth year, arrange the digits in both ascending and descending order, subtract the smaller number from the larger one, and continue the process until they reach the magical number 6174. The number of iterations used in this process is believed to represent their individual lucky number.

 

For instance, if someone has 1977 as the birth year, the following process is applied:

(Note: To apply Kaprekar’s constant, the number should contain at least two different digits, and leading zeros are allowed).

 

  1. Arrange the digits of 1977 in descending order: 9771.
  2. Arrange the digits of 1977 in ascending order: 1779.
  3. Subtract the smaller number from the bigger number: 9771 – 1779 = 7992 (first iteration).
  4. Use the output of Step 3 and apply Steps 1 and 2 another time (second iteration).
  5. Repeat until you get your result 6174.
    1. 9972-2799 = 7173 (second iteration)
    2. 7731-1377 = 6354
    3. 6543-3456 = 3087
    4. 8730-0378 = 8352
    5. 8532-2358 = 6174 (six iterations to get 6174 as a result)

 

If you were born in 1977, according to Serendipity Springs habitants, your lucky number is 6.

 

Long story, right? What is your challenge then?

 

Imagine using Alteryx Designer to validate Kaprekar’s constant and generate your lucky number!

 

Tasks:

 

Task 1: Validate the process that all four-digit integer numbers with at least two distinct digits will transform into 6174 when applying the rules of Kaprekar’s constant.

 

Task 2: Find the highest and the lowest number of iterations you need to transform any four-digit number into 6174 using this rule set.

 

Task 3: Determine your lucky number.

 

HINTS:

You can choose how you want to solve the challenge, but this is the route we would suggest:

 

  • Create an iterative macro to validate the process that all four-digit integer numbers with at least two distinct digits will transform into 6174 when applying the rules of Kaprekar’s constant.

 

  • Create a batch macro that uses your iterative macro to find the highest and the lowest number of iterations you need to transform any four-digit number into 6174 using this rule set.

 

  • Apply the batch macro to a workflow with your birth year to determine your lucky number. (We are using 1977 in our solution.)

 

Wishing you a Happy New Year from Alteryx Academy!

 

May the year ahead be filled with fantastic moments for everyone, and in 2024, get ready for new challenges, updates, and opportunities to strengthen your abilities!

 

Thank you for all your contributions to our Community in 2023!

gawa
16 - Nebula
16 - Nebula

My lucky number was "3"!

Spoiler
image.png
gawa
16 - Nebula
16 - Nebula

Another method by using Generate Row tool without Macro.

 

 

 

 

AkimasaKajitani
17 - Castor
17 - Castor

My solution.

 

Spoiler
スクリーンショット 2023-12-26 144852.png

スクリーンショット 2023-12-26 144908.png

Yoshiro_Fujimori
15 - Aurora

My lucky number is 6 !

 

Spoiler
Main Workflow
main.png
Batch Macro
batch.png
Iterative Macro
iteration.png
Qiu
21 - Polaris
21 - Polaris

Maybe I am just being paranoid, but I somehow smell AOC from this weekly challenge. 🤣

 

Spoiler
Task 1: Veried all 9963 occurence  of number below 10000 containing at least two different digits is consistent with Kaprekar's constant
Task 2: Highest and the lowest number of iterations are 7 and 1
Task 3: My luck number is 6 and I would not say which number it is from.

Challenge_406-Qiu.png
ggruccio
ACE Emeritus
ACE Emeritus

Fun with an iterative macro!  My lucky number is 2!!!

 

Spoiler
406.png
406b.png
Chris-Nienart
8 - Asteroid

Lucky number is 3 for me. Now I need to find another half dozen algorithms to fill out the rest of my lottery ticket.

 

Workflow

Spoiler
I used the L output from the join tool to as a filtering trick.
spoiler-406-1.png

 

Macro

Spoiler
If you treat the number as a word, you can dictionary sort the 'letters' and use string functions to get the ascending and descending numbers.
No numeric comparisons needed!

spoiler-406-2.png
CoG
14 - Magnetar

Lucky Number 6. Feel bad for anyone born in a repeated digit year (e.g. 1111), who have no lucky number :`(

Only need 1 iterative macro (no batch macro):

Spoiler
Main Workflow:
_Main.png
Iterative Macro:
_Iterative.png

I hope y'all had a Merry Christmas and have a Happy New Year! Happy Solving!!!

kelvin_law1
9 - Comet

Here is my solution with iterative macro within a batch macro:

Spoiler
Workflow.png
 

 Iterative Macro:Iterative.png
Batch Macro:
Batch.png