#AdventOfCode #AoC
I (finally!) completed #Day05 of #AdventOfCode2023.
Part 1:
- Difficulty: 4/10
- Workout: 3/10
Part 2:
- Difficulty: 5/10
- Workout: 7/10
Part 1 was completed in 1 hour. Early in the game, I noticed that the mappings, with billions of elements, were too big to fit explicitly in memory. So, I created a function to pass one seed through the mapping, only checking the intervals' end points.
Then part 2 came, with billions of seeds to check. Brute forcing was a lost cause: tried it, lost 2 hours, expected another 6 to be done.
I had to resort to clever set operations (intersection and difference) over intervals: several folks had this idea. Split seed intervals over each mapping: common intervals are mapped to destination intervals, seeds not in common intervals make their own intervals and pass unchanged. The result is a list of intervals, to pass as input "seeds" to the next mapping.
Now part 2 was almost immediate, the seeds having been pulverized into just a few hundred intervals.
Total elapsed time: about 8 hours. Whew!