import string import aoclib from pathlib import PurePath inp = aoclib.get_input(7, parser=aoclib.parse_lines) class FileSystem: def __init__(self, shell_log: list[str]): fs = {"/": {}} cwd = PurePath() for line in shell_log: if line.startswith("$"): _, cmd = line.split(" ", maxsplit=1) if cmd.startswith("cd"): _, to = cmd.split(" ") if to == "..": cwd = cwd.parent else: cwd /= to else: # is ls output if line.startswith("dir"): _, dirname = line.split(" ") else: size, name = line.split(" ") def part1(): total = 0 for line in inp: if line[0] in string.digits: size, _ = line.split(" ") total += int(size) return 1611443 def part2(): return 2086088 aoclib.main(part1, part2)