-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaoc2207.py
54 lines (49 loc) · 990 Bytes
/
aoc2207.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
a = []
with open('2207.0') as file:
# with open('test') as file:
for l in file:
a.append(l.strip())
# print(l)
# print(a)
r = 0
lv = []
sls = '/'
D = dict()
D[sls] = 0
# part 2
top = 4 * 1e7
r2 = 1e9
for l in a:
aa = l.split()
# print(aa)
c = aa[0]
if c == '$':
c = aa[1]
if c == 'cd':
# print('cd', l)
c = aa[2]
if c == '..':
lv.pop()
else:
lv.append(c)
elif c.isnumeric():
# print(' numeric', l)
ll = int(c)
D[sls] += ll
for i in range(len(lv)):
temp = sls
for j in range(i + 1):
temp += lv[j] + sls
if temp not in D:
D[temp] = ll
else:
D[temp] += ll
# part 2
togo = D[sls] - top
for k, v in D.items():
if v < 100000:
r += v
if v > togo:
r2 = min(r2, v)
print('Star 1:', r)
print('Star 2:', r2)