-
-
Save pawlos/bd153a53389ee09e7a8ee6b90ea1f116 to your computer and use it in GitHub Desktop.
Solution to Day 9: Stream Processing - Part 2
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 | |
garbage_count = 0 | |
#print inp | |
for c in inp: | |
print "c:",c, "g:", garbage, "i:", ignore, "l:",level, "s:",score,"ct:",garbage_count | |
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 and not garbage: | |
garbage = True | |
continue | |
if c == ">" and not ignore: | |
garbage = False | |
if c == "!" and garbage and not ignore: | |
ignore = True | |
continue | |
if garbage and not ignore: | |
garbage_count += 1 | |
if ignore: | |
ignore = False | |
print "c:",c, "g:", garbage, "i:", ignore, "l:",level, "s:",score,"ct:",garbage_count | |
#print "----------------" | |
print score, garbage_count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment