Quick actions

cmd+k|ctrl+k

Navigation

Languages

aoc2017-day09

Snippet info

Language

Python

Visibility

public

Author

christophe.guillon.perso

Created

2017-12-09T13:41:40Z

Updated

2017-12-09T13:41:40Z

import sys
import re

input = sys.stdin.read()

st = 0
nest = 0
score = 0
nc = 0
for c in input:
    if st == 0 and c == "{":
        nest += 1
        score += nest
    elif st == 0 and c == "}":
        nest -= 1
    elif st == 0 and c == "<":
        st = 1
    elif st == 1 and c == ">":
        st = 0
    elif st == 1 and c == "!":
        st = 2
    elif st == 1:
        nc += 1
    elif st == 2:
        st = 1

print(nc, score)
INFO