Instantly share code, notes, and snippets.

@pawlos /advent_of_code_d9.py Secret
Last active Dec 24, 2017

Embed
What would you like to do?
Solution to Day 9: Stream Processing - part1
#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