Discussion thread for day 5 of the Advent of Code - https://adventofcode.com/2023/day/5
My brain is dead, but boy was that a fun challenge and a great puzzle! Thinking through how to solve a problem of this magnitude was very exciting (... although I almost crashed my computer, jumping straight to the Generate Rows Tool... Next time I'll check how big the numbers are).
There may be many problems, but I solved them anyway.
Please don't ask me how my WF works, because I can't explain😂
0.9sec with AMP engine.
I refined my WF, and now, I can explain how it works. Happy to achieve less than 1 sec!
Part2 was so hard.
<Macro Part1>
< Macro Part2>
I feel good about my part 1 solve using my multi-row-field-column tool, but part 2 is one of those that you just find a way to solve and move on!
Attached is my sort of cleaned up workflow:
No macro and 1 second to run. Ironically got p2 in a much faster time than P1.
Had to rethink my strategy for part 2 to think in ranges rather than lists. Rough steps are:
1. Check if start of seed range is within one of the source ranges
2. If true, check if the end is within that source range
3. If yes, happy days, assign the offset for the next level
4. If no, break the range into two - the part that fits and the remainder
5. The remainder forms a new range on which to preform steps 1-4.
I used an iterative macro for steps 1-4 and then ran it for each mapping. Runtime 0.5 secs
With a hint from @gawa , I could not come to the solution of Part 2 before going to bed.
This morning I found a way and it worked.
Thanks @gawa (and my good sleep)!
Main
Prep MacroMapping Macro
I revisit my WF and update. I got the clear picture now. WF completes in 0.7sec.
My brain definitely hurts after this one......
Solved. Part 1 worked beautifully but Part 2 failed spectacularly (those Joins seemed like such a good idea during Part 1), so I ended up rebuilding the workflow just for Part 2 with an Iterative Macro (which I probably should've done in the first place). Good fun
Pure brute force. The workflow ran all night and finished 20 min before the AoC Day ended.
5/5 so far.
workflow
My solution.
Part 1 is normal brute force. But that was not working for Part 2. So I made it using range approach.
I did it.
I now hate the world.
Day 5 Part 2 was tricky even with the right "logic". Ranges are easy to conceptualize, but a bit harder to implement... but when it finally works, it solves both parts in 0.6 seconds. 😁
Brute force.
@gawa Nice work on this! By far the most elegant solution I've seen for this challenge.
My heart leapt out of my chest when I ran my first try of part 2 without looking how big the numbers were 😱 But handling the ranges of numbers ended up being a really interesting exercise. I feel like I probably could have used a macro for this, but with the number of steps, I went with brute-force.
At first I believed brutal force and finally getting the result as below. It was an epic failure.Then moved to the Range comparing approach, with some hints from here, I got the answer and I decided to move on even I can not explain the logic in my flow.
Interesting thing is that I am still getting the incorrect answer when I use my input with the most of workflows uploaded here. 😁So I guess its just something we can forget and leave behind and continue our life, continue to be tortured by Day 7 or Day xx. 😅 (Day 6, you are nice), continue to hope to retire to beach one day. @mceleavey
I was on the cusp of solving this one for... many many hours. @PangHC 's workflow looked most similar to my approach, so I ended up having to open that up to help me troubleshoot why I was getting the right answer on the sample data but not my prod data. It was super helpful - even though I was getting the right answer on the sample data, my approach was wrong, and Pang_Hee_Choy's mapping table helped me identify those issues. Thank you for your work!
While going the route of brute force may have gotten me to the answer faster I refused to give in and kept banging my head to get this to run efficiently. Ultimately I succeeded and got my overall run time down to 1.1 seconds.
Part 2 was very difficult.
Macro for part 2
Actually quite proud that I got the solution to part 2! Did have to start all over though as my approach to part 1 was the brute force kind.
Part two is done with a batch and iterative macro and takes less then 2 seconds!
I ran into the same trap as everyone. My is definitely Ugly and I went the range route.
Finally got this done (took a few days to clear out the brain fog).
And built a good few AOC reusable macros in the process!
I post again with solution in yxdb.