Advent of Code 2024 | Day 09 "Disk Fragmenter"

Поделиться
HTML-код
  • Опубликовано: 3 фев 2025

Комментарии • 16

  • @antoineleduc7611
    @antoineleduc7611 Месяц назад

    That part 2 solution is impressive
    Thanks
    I used two sliding windows/two two pointers, one for the first space, one for the last block to switch
    Then swap them if size allow it until switch window is None

  • @vegeta3993
    @vegeta3993 Месяц назад +3

    I got through part one but got stumped on part 2 because I was passing the example but my answer was too high. After seeing your solution I see that while looking at the positions of the blanks I did not handle the case of the position of the blank being after the file position (the if start >= pos check in the while loop). For both cases I did not actually move the files, but rather calculated the checksums there by using the index it would be moved to. I modified the blank spaces the same way though - shrink them if len(file) < len(blank) or pop if len(file) == len(blank)

  • @BillyNix
    @BillyNix Месяц назад

    I can't believe I forgot that the dense representation had the sizes of spaces and files. I was following the example representation. Glad to see you implemented what I realized after I had already submitted my answer.

  • @Skromez
    @Skromez Месяц назад

    hey HyperNeutrino, thank you for sharing your solutions with detailed explanation, i'm sometimes struggling with problems like these, it's easier for me to actually try to modify input to the expected result to make sure i'm doing everything correct, but sometimes that just makes things worse, but your explanation is really helpful to approach the problem from other direction and just coming up with correct data structures, really appreciate it!

  • @oldmajor5240
    @oldmajor5240 Месяц назад +7

    nice! I wrote a really dumb solution naively creating the entire string and simulating everything as said in the problem. to deal with the ids, I just used unicode characters😂😅

  • @MrRys
    @MrRys Месяц назад +2

    nice solution, I saved the memory as pairs of id(blank id=-1) and size, and then just switched the ids and sizes in a loop

  • @bencered
    @bencered Месяц назад

    Awesome stuff! This solution is a lot more efficient than mine... (Took about an hour to run)

  • @griffinbaker860
    @griffinbaker860 Месяц назад +2

    here's the gaussian solution for the last part for anyone curious:
    *SPOILER*
    print(
    sum(fid * size * (pos + pos + size - 1) // 2 for fid, (pos, size) in files.items())
    )

  • @yajusgakhar6969
    @yajusgakhar6969 Месяц назад

    My solution was (for part 1):
    Make an array of all the files,
    Start adding (val * index)
    If find a blank, add the (last element * index)
    As you add the values, pop them out of the list
    Essentially blank meant add from behind or the end of the list
    Still fixing my logic for part 2

  • @terryaney73
    @terryaney73 Месяц назад

    You ever post your run times? Curious how much slower my typescript version runs compared to your python :)

    • @hyper-neutrino
      @hyper-neutrino  Месяц назад

      i could consider benchmarking but i don't have a reliable and consistent setup for that but i could. also your solution is probably faster, JS/TS is significantly faster than python in my experience

    • @terryaney73
      @terryaney73 Месяц назад

      @@hyper-neutrino Didn't know that about speed, but also my solutions aren't always same as yours. But anyway, don't need rocket science precision, but if you ever feel like it, just mention in video after running. `aoc` "...and that gives us our answer in about X ms" :)

  • @kedarshinde4216
    @kedarshinde4216 Месяц назад

    very unrelated but what font do you use in vscode it looks cool

    • @hyper-neutrino
      @hyper-neutrino  Месяц назад

      that's monaspace krypton: monaspace.githubnext.com/

  • @SqueezeWizard
    @SqueezeWizard Месяц назад

    For part 2, I think blanks = blanks[:i] is basically useless (doesn't really make it faster), but blanks.pop(i) makes it like 10x faster! nice, i wasn't expecting it