Skip to content

Instantly share code, notes, and snippets.

@pawlos
Last active December 24, 2017 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlos/bd153a53389ee09e7a8ee6b90ea1f116 to your computer and use it in GitHub Desktop.
Save pawlos/bd153a53389ee09e7a8ee6b90ea1f116 to your computer and use it in GitHub Desktop.
Solution to Day 9: Stream Processing - Part 2
#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