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.
 
 

29 lines
722 B

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])
for s in sizes:
if sizes[s] <= 100000:
sum += sizes[s]
print(sum)