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)
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
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.
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😂😅
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!
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()) )
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
@@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" :)
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
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
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)
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
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.
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😂😅
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!
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
Awesome stuff! This solution is a lot more efficient than mine... (Took about an hour to run)
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())
)
You ever post your run times? Curious how much slower my typescript version runs compared to your python :)
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
@@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" :)
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
very unrelated but what font do you use in vscode it looks cool
that's monaspace krypton: monaspace.githubnext.com/
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