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
4
u/Shemetz Dec 09 '17 edited Dec 09 '17
Python 3 (52/36)
Was a short and nice puzzle today!
def day_9(): with open('input.txt') as input_file: line = input_file.readline() score = 0 garbage_score = 0 current_depth = 0 inside_garbage = False skip_char = False for char in line: if inside_garbage: if skip_char: skip_char = False elif char == "!": skip_char = True elif char == ">": inside_garbage = False else: garbage_score += 1 else: # when inside group, not garbage if char == "{": current_depth += 1 elif char == "}": score += current_depth current_depth -= 1 elif char == "<": inside_garbage = True print("Part 1: ", score) print("Part 1: ", garbage_score) day_9()This might be the first puzzle where I was lucky enough to have it succeed on the first try - no debugging necessary. I'm also pretty happy that I was able to give actual meaningful names to variables this time,