Range overlap and intersection - Day 05 - Advent of Code

In this episode, you’ll learn how to solve the tricky Day 5 advent of code challenge involving massive number ranges and mapping "seeds" to "locations". I parse the input data into seeds and conversion rule groups. Then build a find method to apply offsets from each group's ranges.

For part 1, we'll traverse the groups to map a seed to its lowest possible location number. Part 2 requires handling seed ranges, so we create a convert method to break ranges into intersecting sub-ranges with offsets. By tracking these in a nested array, we cascade through each step without exploding memory.

The core solution leverages custom range intersection and set logic to avoid iterating impossible quadrillions of numbers. We’ll change the Range object with monkey-patching to add overlaps? and intersection methods.

Advent of Code: https://adventofcode.com/
My Solutions: https://gist.github.com/cjavdev/d15a2a4ffed6c840c2fb28a093e9f927/
Playlist https://www.youtube.com/playlist?list=PLS6F722u-R6KYlGyUv65EFpGKl2Esmurr

#adventofcode #ruby