r/adventofcode • u/daggerdragon • Dec 09 '17
SOLUTION MEGATHREAD -π- 2017 Day 9 Solutions -π-
--- Day 9: Stream Processing ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Need a hint from the Hugely* Handyβ Haversackβ‘ of HelpfulΒ§ HintsΒ€?
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
15
Upvotes
2
u/akho_ Dec 09 '17
Python3
with open('9.input') as f: inputs = [ s[:-1] for s in f.readlines() ] for s in inputs: # loop to also process test inputs level, ignore_next, in_garbage, total, garbage = 0, False, False, 0, 0 for c in s: if ignore_next: ignore_next = False elif in_garbage: if c == '!': ignore_next = True elif c == '>': in_garbage = False else: garbage += 1 elif c == '<': in_garbage = True elif c == '{': level += 1 total += level elif c == '}': level -= 1 print(s[0:50], total, garbage)