Discussion thread for day 5 of the Advent of Code - https://adventofcode.com/2024/day/5
My solution involved a sneaky trick that helped solve part 1 and set me up nicely for part 2:
D5 was tricky; more in the spoiler
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,
Solved!
a good challenge.
Couldn't really explain to you why the Part 2 iterative macro logic worked... but it worked!
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!
Almost brute force approach to find the correct path among all patterns. I need to refine this later.
Since now I can't fall asleep... decided to come post this now while I'm still up.
A bit of a brute force approach that switches the incorrect pairs one at a time. It works but is slow!
Workflow:
Macro:
5 days in and still no macros used for me! I had a nice realisation about the logic which helped massively for part 2, not sure if it's a totally sustainable solution, as I feel like the iterative approach properly solves the problem, but my idea with the logic worked for my input...!
Very happy with my brain today in solving this one. Zero MACROS. This is the day where I feel like I can do Advent of Code. Best buy tissues for tomorrow.
2024 Day 5 is very hard to me.
Another tricky one today. Feels like difficulty is starting to ramp up.
A few little tricks to this one, but not too bad!
(Since the connections were a little more tangled today compared to previous days, it was a good excuse to try the new connection color options in 2024.2!)
Colored connection lines out in the wild! Looks great, @matthewblandford !! ❤️
My solution.
Certainly no awards for creativity/tool golf today but we got there!
This was a fun one. I don't know why my mind force me to have a iterative inside a batch macro...
part 1 and 2 main workflow
part 1 macro
part 2 macro
Marcus Alvim
Went too greedy at the first try, wanted to create the master ordered list, too many layers of macro.
Luckily cleared my ahead for a different direction, turns out much easier way.
Day 5 P2 was an challenging task for me. Regarding P2, I referred to @Samantha_Jayne 's workflow. Her workflow was truly outstanding and something I couldn't replicate.
This was a tough one.... the way i did it for P1 wouldnt work for P2 so need to rethink design.
@Samantha_Jayne This is so elegant. Thank you for sharing.I went to complete oposite direction as Max Macro, Batch + Iterative.I have downloaded your flow for leaning.AoC is all about the logic, I guess.
@Samantha_Jayne Can I have a question about your flow?The questions states below
(47 doesn't necessarily need to be immediately before 53; other pages are allowed to be between them.)
But in your "Rule in Input" variable, it appears that your assume that the pages are always immediately next to each other.I did run my data, and your workflow is actually giving the correct answer.I am really wondering why. can you enlighten me? Thanks.
Finally got this one figured out!
I solved Part 1 by checking each page number in the update against each rule relevant to that page number, and comparing the index of one against the other.
I got extremely stuck on Part 2, and didn't have time to give it much thought before tonight. Luckily, I think the mental break is what I needed. I realized that I don't actually need to reorder anything, I just needed to identify which element was in the MIDDLE. Luckily, every instruction set had one page number that by definition had to be in the middle!
I'm eager to see everyone else's elegant solutions, and to give thought to reworking this one. This wasn't my favorite but it was a good challenge.
This was a lesson in walking away and coming back with fresher eyes. Sometimes it helps to stop and ask - what do I really need to do here.
Alas - no fancy macros or iterations. The result may not be completely robust but it got the job done.
Solved! For Part 2, I was struggling with how to proactively figure out the right order. After futzing with it for awhile, I gave up and went with an iterative macro inside of another iterative macro.
In the inner iterative macro, I started at the left of each "update" and checked to see if page 1 and page 2 were in a good or bad order. If bad, I switched. If good, I left alone. Then I checked if the entire line was resolved. If not, I checked page 2 against page 3. And then for any where I got to the end and they still had problems, I sent them back through the inner iterative macro, and just repeated until they were in the right order.
Definitely not the most efficient way to solve it, but the entire workflow runs in 3.1 seconds so I'm calling that good enough
Outer macro:
Inner macro:
Was really overthinking the resort in part 2 and then think I stumbled into some dumb luck while exploring the data.
First iterative one
a sorta-brute-force solution - almost like a sorting algorithm
Checker:
Iterative Fixer:
Python code for Day 5:
All code at SeanAdams10/AdventOfCodePython: Advent of code challenges in Python - across multiple years
Part 1 was easy for me to understand. Part 2 not so much, but got through