File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
puzzles/solutions/2022/d07 Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 11import sys
22
3+ import consts
4+ import p1
5+
36
47def get_answer (input_text : str ):
5- raise NotImplementedError
8+ """Return total size of the smallest directory that, if deleted, would free up enough space on the filesystem."""
9+ filesystem = p1 .get_filesystem (input_text )
10+ root = filesystem [0 ]
11+ total_used_space = root .size
12+ unused_space_needed = consts .REQUIRED_UNUSED_SPACE - (consts .TOTAL_DISK_SPACE - total_used_space )
13+ candidate_directories = (directory for directory in filesystem if directory .size >= unused_space_needed )
14+ directory_to_delete = min (candidate_directories , key = lambda directory : directory .size )
15+ return directory_to_delete .size
616
717
818if __name__ == "__main__" :
You can’t perform that action at this time.
0 commit comments