This repository was archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.py
More file actions
64 lines (55 loc) · 1.37 KB
/
Copy path7.py
File metadata and controls
64 lines (55 loc) · 1.37 KB
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
64
import dpath
import json
def mkdir(list, path, name):
pass
def total_folder(dir):
global full_total, dir_sizes
total = 0
for i in dir.values():
if type(i) == type(1): # bad
total += i
else:
_ = total_folder(i)
dir_sizes.append(_)
total += _
if _ < 100000:
full_total += _
return total
with open('7.txt', 'r') as f:
commands = f.read().splitlines()
# I cannot be assed to do this the correct way so imma do it dumb
dir_sizes = []
full_total = 0
files = {}
pwd = []
mode = 'command'
for command in commands:
c = command.split(' ')
# print(c)
if c[0] == '$':
if c[1] == 'cd':
if c[2] == '..':
pwd.pop(len(pwd)-1)
else:
pwd.append(c[2])
elif c[1] == 'ls':
tmp_pwd = pwd.copy()
# print('a')
if len(c) == 3:
tmp_pwd.append(c[2])
else:
try:
dpath.new(files, '/'.join(tmp_pwd)+'/'+c[1], int(c[0]))
except:
pass
#dpath.new(files, '/'.join(tmp_pwd)+'/'+c[1], int(c[0]))
#print(json.dumps(files, indent=4))
used = total_folder(files)
unused = 70000000 - used
dir_sizes.sort()
# dir_sizes.reverse()
for i in dir_sizes:
if i + unused > 30000000:
print(i)
break
# print(full_total)