Range overlap and intersection - Day 05 - Advent of Code
Вставка
- Опубліковано 27 сер 2024
- 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: adventofcode.com/
My Solutions: gist.github.co...
Playlist • Advent of Code
#adventofcode #ruby
Thank you. I tried the first part using hashes, and it worked with the the small example data. I was so proud of myself, but then I discovered that with the real input I could wait for years. 😆
I totally thought that approach would work too.
At 9:00: got a question here. Why you over complicate the process? Why don't you just return the seed number instead as explained in the topic? I actually did the part one but with error and can't figure it.
The 2º puzzle defeated me. In two days I wrote two pieces of code that work perfectly with example, but won't give me the right answer for my input file.
Third piece of code is working. I don't know why yesterday's don't want to work, slightly not sure why today's is working. 🤣
I did both parts but part2 is so slow for ruby! It takes 25 hours to complete xD who invented those task is crazy