-
-
Save pawlos/71a270fdef94404734b383f6e3cb2301 to your computer and use it in GitHub Desktop.
Solution to Day 9: Stream Processing - part1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#aoc_d9.py | |
score = 0 | |
inp = open("input_d9.txt","r").read() | |
#"{{<ab>},{<ab>},{<ab>},{<ab>}}" | |
#"{{{},{},{{}}}}" | |
#"{{<a!>},{<a!>},{<a!>},{<ab>}}" | |
#"{{<!!>},{<!!>},{<!!>},{<!!>}}" | |
level = 0 | |
garbage = False | |
ignore = False | |
#print inp | |
for c in inp: | |
#print "c:",c, "g:", garbage, "i:", ignore, "l:",level, "s:",score | |
if c == "{" and not garbage: | |
#opening a group | |
level += 1 | |
if c == "}" and not garbage: | |
#closing a group | |
score += level | |
level -= 1 | |
if c == "<" and not ignore: | |
garbage = True | |
if c == ">" and not ignore: | |
garbage = False | |
if c == "!" and garbage and not ignore: | |
ignore = True | |
continue | |
if ignore: | |
ignore = False | |
#print "c:",c, "g:", garbage, "i:", ignore, "l:",level, "s:",score | |
#print "----------------" | |
print score |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment