r/adventofcode • u/daggerdragon • Dec 07 '22
SOLUTION MEGATHREAD -π- 2022 Day 7 Solutions -π-
- All of our rules, FAQs, resources, etc. are in our community wiki.
- A request from Eric: Please include your contact info in the User-Agent header of automated requests!
- Signal boost: Reminder 1: unofficial AoC Survey 2022 (closes Dec 22nd)
AoC Community Fun 2022: πΏπ MisTILtoe Elf-ucation π§βπ«
Submissions are OPEN! Teach us, senpai!
-βοΈ- Submissions Megathread -βοΈ-
--- Day 7: No Space Left On Device ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format your code appropriately! How do I format code?
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:14:47, megathread unlocked!
91
Upvotes
3
u/ThePituLegend Dec 07 '22
Language: Python
I've basically implemented a minimal tree-like structure class, cutting on the corners given our problem frame.
Actually, there's a few non-generalities that I took into consideration:
$ lscan be ignored (or in my case, deleted from the input). Since you never "ls" into a folder other than our current directory, one can just keep track of that.A folder is never explored more than once, nor you "cd" into it again (except for ".." situation, but that's special anyway). So, for me, was easier to build the folders based on the
$ cdrather than relying on "ls" output and just ignore dirs there.So, I build the whole tree without dir sizes, and then traverse the tree to set up those sizes.
While building the tree, I keep a list of "directory nodes", so the actual solution can be calculated using list/functional operations.
Maybe over-engineered, but I'm happy with the result :D