Advent of Code 2024 | Day 09 "Disk Fragmenter"

Поділитися
Вставка
  • Опубліковано 14 січ 2025

КОМЕНТАРІ • 16

  • @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)

  • @antoineleduc7611
    @antoineleduc7611 28 днів тому

    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

  • @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.

  • @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😂😅

  • @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!

  • @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())
    )

  • @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" :)

  • @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

  • @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