-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.py
More file actions
29 lines (27 loc) · 759 Bytes
/
9.py
File metadata and controls
29 lines (27 loc) · 759 Bytes
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
#!/usr/bin/python3
if __name__ == "__main__":
with open("9") as dfile:
data = dfile.read()
counter = 0
depth = 0
score = 0
garbage = False
garbagecounter = 0
while counter < len(data):
if data[counter] == "!":
counter += 2
continue
elif garbage and data[counter] != ">":
garbagecounter += 1
elif garbage and data[counter] == ">":
garbage = False
elif data[counter] == "<":
garbage = True
elif data[counter] == "{":
depth += 1
score += depth
elif data[counter] == "}":
depth -= 1
counter += 1
print("Solution 1:", score)
print("Solution 2:", garbagecounter)