-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay7_part1.py
34 lines (34 loc) · 876 Bytes
/
Day7_part1.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
File = open("Day_7_Input.txt", "r")
from collections import defaultdict
Lines = File.readlines()
FileTree = defaultdict(int)
CWD = []
for line in Lines:
if "$ cd" in line:
if ".." in line:
CWD.pop()
else:
directory = line.replace("$ cd","").strip()
CWD.append(directory)
print(CWD)
elif "$ ls" in line:
continue
elif "dir" in line:
continue
else:
# try:
size = int(line.split(" ")[0])
print(line)
for i in range(len(CWD)):
print(i,CWD[i])
print("/".join(CWD[:i+1]))
FileTree["/".join(CWD[:i+1])] += size
# except:
# pass
print(FileTree)
ans = 0
for ele in FileTree:
print(ele, FileTree[ele])
if FileTree[ele] <= 100000:
ans += FileTree[ele]
print(ans)