34 lines
826 B
Python
34 lines
826 B
Python
def part_1(data):
|
|
i = 0
|
|
group_score, garbage_score = 0, 0
|
|
in_garbage = False
|
|
group_level = 0
|
|
while i < len(data):
|
|
match data[i]:
|
|
case "{" if not in_garbage:
|
|
group_level += 1
|
|
case "}" if not in_garbage:
|
|
assert group_level > 0
|
|
group_score += group_level
|
|
group_level -= 1
|
|
case "<" if not in_garbage:
|
|
in_garbage = True
|
|
case ">" if in_garbage:
|
|
in_garbage = False
|
|
case "!" if in_garbage:
|
|
i += 1
|
|
case _ if in_garbage:
|
|
garbage_score += 1
|
|
i += 1
|
|
print(group_score)
|
|
print(garbage_score)
|
|
|
|
|
|
def main():
|
|
data = open(0).read().strip()
|
|
part_1(data)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|