Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2022 - Day 7 #208

Merged
merged 8 commits into from
Dec 9, 2022
Merged

2022 - Day 7 #208

merged 8 commits into from
Dec 9, 2022

Conversation

romellem
Copy link
Owner

@romellem romellem commented Dec 9, 2022

Hardest one yet! Decided to do what I normally do for these: OOP.

  • Created a File and Dir class, and just for fun, a Filesystem class that mostly handles parsing of the input, and some sugar for iterating over the file tree.
  • Parsing is pretty basic: startsWith checks for what kind of line we are looking at, and regex to extract name and size values.
  • Determining size of directories is done with recursion: both Files and Dirs have a size() method. When a Dir's size() is call, we say its the size of its contents sizes added up. Its contents can either be files or dirs, so if it is a dir, that's where we see the recursion.
  • Finally, for part two, I add an argument to the size() method to ignore an item's size. If the thing we are looking at is what we should ignore, we immediately return 0. So for dirs, it doesn't recursive through its tree.

@romellem romellem merged commit f96b15b into master Dec 9, 2022
@romellem romellem deleted the 2022/day-7 branch December 9, 2022 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant