07 løsning

This commit is contained in:
Rasmus Malver 2022-12-07 17:14:31 +01:00
parent f7d0407080
commit 65c350d7b4
2 changed files with 1074 additions and 0 deletions

29
07/2022-12-07-AB.py Normal file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env python3
space = {"/":0}
loc = ["/"]
for c in open("07/i").read().split("$"):
if c[0:6]==" cd ..":
loc.pop()
elif c[0:5]==" cd /":
loc = ["/"]
elif c[0:4]==" cd ":
loc.append(c.strip().split(" ")[1])
elif c[0:3]==" ls":
for l in c.strip().split("\n")[1:]:
txloc = "/".join(loc) if len(loc)>1 else "/"
if l[0:3]=="dir":
new_dir = "/".join([txloc,l.split(" ")[1]])
space[new_dir] = 0
else:
val = int(l.split(" ")[0])
space[txloc] += val
for i in range(1,len(loc)):
space["/".join(loc[:i])]+=val
print(sum(filter(lambda x: x<100000,space.values())))
print(sorted([(v, k) for k, v in space.items() if v > 30000000-(70000000-space["/"])])[0][0])

1045
07/i Normal file

File diff suppressed because it is too large Load diff