Advent of Code 2022 Day 7 (#18/#14) Walk-Through

preview_player
Показать описание

Please attempt the problem on your own before watching this video!
Рекомендации по теме
Комментарии
Автор


This video better reflects my thought process and how I solved it live during the contest, not what I could have come up with afterwards, but there is a much more elegant solution and I would highly recommend you to check out Viliam's answer as well.

hyper-neutrino
Автор

Thanks for these nice videos. I'm a bit late to the party, but watching after I finish the puzzles.

I think your solution is maybe more sound than mine, but I think (for the first time), that I found a faster one to implement.

I did a stack much like you, but instead of a nested directory, I used a directory of ints.

So the directory would have '/':size, '/a/': size, '/a/e/':size and so on.
I would then just add the value to every directory in the stack.
That meant that I could just work on folders.values
Instead of solving like you do in the video.

I've learned a lot from doing the puzzles and watching, so thanks for taking your time to do these 8-)

awwkaw
Автор

I have been watching everyday and seeing your thought process really helps me solve these questions faster. I made it to top 1k for the first time today so thank you for all the AOC videos!

nexxel
Автор

I couldn't for the life of my figure out how to just use a dictionary (wish I had), so I build a Dir class with members name, parent, children, size (of it's files only)... then kept a reference to all the known directories and used this to construct a list of each of the sizes of each of the folders using a recursive function and traversed the tree of Dir objects adding up the file-size, running it on every seen folder (lots of space complexity), then I just filtered the values for part 1 and filtered and sorted the values for part 2. The thing our solutions have going for them is they can handle randomness in the input (e.g. unnecessary navigational steps in the CLI input).

I like your AOC launcher/tester approach. Nice and minimal, especially how it makes you use the sample input as well as the main puzzle input.

appuser
Автор

hyper-neutrino: don't over optmize
me: waste 5 minutes on stupid bug the day after when trying to write optimal solution

khoda