-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathd7.py
63 lines (56 loc) · 1.35 KB
/
d7.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
data = [ x.strip('\n') for x in open("i7.txt").readlines() ]
# data = [ x.strip('\n') for x in open("t7.txt").readlines() ]
stack = []
cwd = []
ls = []
sss = 0
lss = 0
from collections import defaultdict
d = defaultdict(int)
for l in data:
first, second, *parts = l.split()
if first == '$':
print(cwd, ls)
ss = sum([ int(s[0]) for s in filter(lambda x: x[0].isnumeric(), ls)])
d['/'.join(cwd)] += ss
if second == 'cd':
ls = []
if parts[0] == "/":
cwd = []
elif parts[0] == "..":
x = d['/'.join(cwd)]
cwd = cwd[:-1]
d['/'.join(cwd)] += x
else:
cwd.append(parts[0])
elif second == 'ls':
ls = []
pass
else:
assert False
else:
ls.append([first, second])
ss = sum([ int(s[0]) for s in filter(lambda x: x[0].isnumeric(), ls)])
d['/'.join(cwd)] += ss
while cwd:
x = d['/'.join(cwd)]
cwd = cwd[:-1]
d['/'.join(cwd)] += x
s2 = 0
for cwd,s in d.items():
print(cwd,s)
if s <= 100000:
s2 += s
print(s2)
total = 70000000
need = 30000000
current = d[""]
unused = total - current
print(unused)
freeup = need - unused
print(freeup)
c = []
for cwd,s in d.items():
if s >= freeup:
c.append((s, cwd))
print(sorted(c))