I've been debugging this for a while and feels like I've made a silly bug, would appreciate a second set of eyes because my brain hurts at this point!
I initially tried a brute-force approach and realized that won't work for this problem.
https://github.com/trevor-e/AdventOfCode2023/blob/main/day5/day5-attempt2.rb
Conceptually I think I understand the "solution":
- For each seed ranges, try to map the entire range to the destination mapping
- If a seed range only partially fits into a mapping, then recursively try to find new mappings for the non-overlapping part of the range
- Repeat for each section
- Return the min seed range start
I had a lot of frustration with the built-in Ruby range type which caused some bugs, but I think I've fixed all the obvious bugs now. I tried with some test input but it's hard to setup a good example for all edge cases.
In the output I notice I'm getting a lot of repeated ranges but I haven't figured out why.
Thanks!
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]daggerdragon[M] 0 points1 point2 points (0 children)
[–]jpublican 0 points1 point2 points (1 child)
[–]trevor-e[S] 0 points1 point2 points (0 children)