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

КОМЕНТАРІ • 6

  • @antoniog2859
    @antoniog2859 8 місяців тому +1

    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. 😆

    • @cjav_dev
      @cjav_dev  8 місяців тому +1

      I totally thought that approach would work too.

  • @user-sb8ls5rs4v
    @user-sb8ls5rs4v 8 місяців тому +1

    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.

  • @piotrtalarczyk8987
    @piotrtalarczyk8987 8 місяців тому +1

    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.

    • @piotrtalarczyk8987
      @piotrtalarczyk8987 8 місяців тому

      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. 🤣

  • @lappi_wojak
    @lappi_wojak 6 місяців тому

    I did both parts but part2 is so slow for ruby! It takes 25 hours to complete xD who invented those task is crazy