You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
877 B

11 months ago
lines = [[l.split(" ") for l in m.splitlines()] for m in open("input.txt", 'r').read().split("$ ")][1:]
path = ["/"]
sizes = {"/":0}
sum = 0
for l in lines:
if l[0][0] == "cd":
if l[0][1] == "/":
path = ["/"]
elif l[0][1] == "..":
path.pop()
else:
path.append(l[0][1]+"/")
elif l[0][0] == "ls":
for i in range(1,len(l)):
if l[i][0] == "dir":
sizes["".join(path) + l[i][1]+"/"] = 0
else:
sofar = ""
for p in path:
sofar += p
sizes[sofar] += int(l[i][0])
11 months ago
min = sizes["/"] + 30000000 - 70000000
smallest = sizes["/"]
11 months ago
for s in sizes:
11 months ago
size = sizes[s]
if size <= 100000:
sum += size
if size >= min and size < smallest:
smallest = size
11 months ago
11 months ago
print(sum)
print(smallest)