parent
3a7a4fbfd1
commit
e592f3d931
1 changed files with 29 additions and 0 deletions
@ -0,0 +1,29 @@ |
||||
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) |
Loading…
Reference in new issue