-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday09.py
More file actions
41 lines (32 loc) · 755 Bytes
/
day09.py
File metadata and controls
41 lines (32 loc) · 755 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
30
31
32
33
34
35
36
37
38
39
40
def calc(input):
score = 0
level = 0
i = 0
garbage = 0
while i < len(input):
c = input[i]
if c == '!':
i += 2
continue
if c == '<':
while c != '>':
if c == '!':
i += 2
c = input[i]
else:
i += 1
c = input[i]
garbage += 1 if c != '>' and c != '!' else 0
if c == '{':
level += 1
if c == '}':
score += level
level -= 1
i += 1
return score, garbage
def calc_a(input):
score, _ = calc(input)
return score
def calc_b(input):
_, garbage = calc(input)
return garbage