Skip to content

Commit

Permalink
Add function that size of the smallest directory that should be deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
katzuv committed Dec 17, 2022
1 parent f15e860 commit ba1ead8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion puzzles/solutions/2022/d07/p2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import sys

import consts
import p1


def get_answer(input_text: str):
raise NotImplementedError
"""Return total size of the smallest directory that, if deleted, would free up enough space on the filesystem."""
filesystem = p1.get_filesystem(input_text)
root = filesystem[0]
total_used_space = root.size
unused_space_needed = consts.REQUIRED_UNUSED_SPACE -(consts.TOTAL_DISK_SPACE - total_used_space)
candidate_directories = (directory for directory in filesystem if directory.size >= unused_space_needed)
directory_to_delete = min(candidate_directories, key=lambda directory: directory.size)
return directory_to_delete.size


if __name__ == "__main__":
Expand Down

0 comments on commit ba1ead8

Please sign in to comment.