-
Notifications
You must be signed in to change notification settings - Fork 0
/
7.py
54 lines (43 loc) · 1.27 KB
/
7.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
with open('input7','r') as f:
sizedir = {"root": 0}
peres = {"root":None}
curdir = "root"
f.readline()
while True:
ligne = f.readline()
if ligne == '': break
elif '$ ls' in ligne:
continue
elif '$ cd' in ligne:
gotodir = ligne.split('cd')[1][1:-1]
if gotodir != '..':
curdir = curdir + '/' + gotodir
else:
curdir = curdir[::-1].split('/',1)[1][::-1]
elif 'dir ' in ligne:
newlocaldir = ligne.split('dir')[1][1:-1]
newdir = curdir + '/' + newlocaldir
peres[newdir] = curdir
if newdir not in sizedir: sizedir[newdir] = 0
else:
taillefich = int(ligne.split(' ')[0])
suiteperes = curdir
sizedir[suiteperes] += taillefich
while suiteperes != 'root':
suiteperes = peres[suiteperes]
sizedir[suiteperes] += taillefich
#7a
tot = 0
for x in sizedir.items():
taille = x[1]
if taille <= 100000:
tot += taille
print(tot)
#7b
capa = 70000000
needdel = 30000000 -(capa - sizedir['root'])
from math import inf
rep = inf
for x in sizedir:
if sizedir[x]>needdel and sizedir[x]<rep: rep = sizedir[x]
print(rep)