Free Trial

General Discussions

Discuss any topics that are not product-specific here.

Advent of Code 2024 Day 5 (BaseA Style)

AlteryxCommunityTeam
Alteryx Community Team
Alteryx Community Team

Discussion thread for day 5 of the Advent of Code - https://adventofcode.com/2024/day/5

39 REPLIES 39
CoG
14 - Magnetar

My solution involved a sneaky trick that helped solve part 1 and set me up nicely for part 2:

 

Spoiler
Instead of looking for page collections that are in the correct order, I can instead identify all collections that have at least one order rule violation. If I know that set, then the remaining collections must be in the correct order:

Main.png

For part 2 I used an iterative macro to sort pages:
Sort Pages Macro.png

 

mmontgomery
11 - Bolide
11 - Bolide

D5 was tricky; more in the spoiler

Spoiler
P1 approach was to take the instructions and split them into rows then do a find/replace to match pairs from top data (26|58 in bottom to top). I filtered out groups that didn't match all pairings based on null append from find/replace
P2 was similar-ish since I filtered to non-matches only. Then I did a reverse order on paths (originally did find/replace on name/value pair 26|58 but this time I did it reverse order 58|26, as an example that didn't match in the overall grouping.) Then I did a count of which values showed up in the first column most frequently, then added the most common result from the second column (last item), ordered them, took the median, self join and sumday5_P1.pngday5_P2.png
day5_P2_formula.png

day5_P2_run.png

 

ScottLewis
11 - Bolide

More on this tomorrow, after sleep and some cleanup but if you have a part 1 that works for the sample data but not the real data, 

 

Spoiler
It is possible that, like me, you failed to account for the possibility of duplicate strings. Record ID is your friend.
AkimasaKajitani
17 - Castor
17 - Castor

Solved!

 

Spoiler
At first, I had no idea how to solve Part 2. In the end, I concluded that I should use an Iterative macro to repeat the problem until there were no more cases that did not meet the conditions.

image.png

image.png

PangHC
12 - Quasar

a good challenge. 

Spoiler
part1: assign recordID and split to rows and use join to compare all to all. use position to generate the "29|13" or "13|29". and join with the dictionary. if any pair not match, mean this recordID is not sort properly exclude it. 
for the rest, get the middle data and sum it.

part2: use iteration macro for logic in part 1. and adjust the position for the missout part by exchange the position i.e. "29, 13" to "13, 29". just pair by pair per recordID. Iterate until fully sort.
To get the answer for part 2, use iteration.number >0 to remove the part1 answer. 
Screenshot 2024-12-05 144037.png
NicoleJ
Alteryx
Alteryx

Couldn't really explain to you why the Part 2 iterative macro logic worked... but it worked! 

 

Spoiler
Day5NJ.png

For Part 2, I accidentally stumbled upon something that worked... I think it has something to do with seeing which values only show up in the "before" page rules vs. the "after" page rules, then whittling those down until there's no rules left? So like if page 13 only shows up in the "before" column, that means it's the first page... same if 89 only shows up in the "after" column, that means it's the last page... and then if you remove that from the list, you'll have a new "last page" left in the rules that remain? I think? It's late, I'm not actually sure, but that sounds pretty legit. 😂

Today's "new Designer feature" win: Using GetPart formula (with a count of delimiters / 2 for the index) to find the middle value!

 

Cheers!
NJ
Sr. Manager, Product Management, Designer
Alteryx
gawa
16 - Nebula
16 - Nebula

Almost brute force approach to find the correct path among all patterns. I need to refine this later.

 

Hub119
11 - Bolide
11 - Bolide

Since now I can't fall asleep... decided to come post this now while I'm still up.

Spoiler
AoC D5 Pic.png
geoff_zath
Alteryx
Alteryx

A bit of a brute force approach that switches the incorrect pairs one at a time. It works but is slow!

 

Workflow:

Spoiler
AoC_2024_day4.png

Macro:

Spoiler

AoC_2024_day4_macro.png

Labels
Top Solution Authors