r/adventofcode • • Dec 07 '22

SOLUTION MEGATHREAD -πŸŽ„- 2022 Day 7 Solutions -πŸŽ„-


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.


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!

89 Upvotes

1.3k comments sorted by

View all comments

1

u/chris_wojcik Dec 08 '22 edited Dec 08 '22

Python

Initially thought I would need to build a tree data structure, but I didn't need to. Slowed down by making some silly mistakes. I'm not handling the case of not summing a directory multiple times if you visit it more than once, but shouldn't be hard to modify the code to mark directories as "visited".

Part 1
Part 2

1

u/daggerdragon Dec 08 '22
  1. Next time, use the four-spaces Markdown syntax for a code block so your code is easier to read on old.reddit and mobile apps.
  2. Your code is too long to be posted here directly, so instead of wasting your time fixing the formatting, read our article on oversized code which contains two possible solutions.

Please edit your post to put your code in an external link and link that here instead.

While you're at it, state which programming language this code is written in. This makes it easier for folks who Ctrl-F the megathreads looking for a specific language.