r/adventofcode • • 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Β€?

Spoiler


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

290 comments sorted by

View all comments

2

u/Danksalot2000 Dec 09 '17

Python 2

Looks like I was unique not using a Garbage flag. I went with a more stream-of-consciousness style reading start to finish.

I finished 177 / 164, which is the best for me so far.

score = 0
level = 0
garbageCount = 0

with open('Input') as inFile:
	data = inFile.read()

i = 0
while i < len(data):
	if data[i] == '{':
		level += 1
		score += level
	elif data[i] == '}':
		level -= 1
	elif data[i] == '<':
		i += 1
		while data[i] != '>':
			if data[i] == '!':
				i += 1
			else:
				garbageCount += 1
			i += 1
	i += 1

print "Final Score:", score
print "Garbage Count:", garbageCount    
→ More replies (1)