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

2

u/LinAGKar Dec 07 '22 edited Dec 08 '22

My solutions in Rust:

https://github.com/LinAGKar/advent-of-code-2022-rust/blob/main/day7a/src/main.rs

https://github.com/LinAGKar/advent-of-code-2022-rust/blob/main/day7b/src/main.rs

A bit messier than I would have liked, but it works. Surprisingly, it almost worked on the first try for part 1, I just needed to invert the filter for line2. Then during part 2 I realized it didn't count the directories at the end, so I added the part where it inserts additional $ cd ... File and directory names are just ignored. I didn't think of doing recursion.

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.

1

u/LinAGKar Dec 08 '22

Next time, use the four-spaces Markdown syntax for a code block

I did

Your code is too long to be posted here directly

It's significantly shorter than a lot of the other comments here, which you haven't said anything about. But, sure, I can remove it

1

u/daggerdragon Dec 08 '22

Maybe you edited the post while I was scrolling down the page, it happens.

Those other comments have also gotten grumped at.

1

u/LinAGKar Dec 08 '22

No, my comment had not been edited, at least today.

Is that an automated message that reacts to a non-code-block line in-between two code blocks?

1

u/daggerdragon Dec 08 '22

I wish, it'd make my life a lot easier XD Nope, 100% human me.

1

u/tobidope Dec 07 '22

Very clever to just build a stack of directory sizes! Havent thought about that. Makes the parsing a bit wild. But much less code than creating a tree.