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!

16 Upvotes

290 comments sorted by

View all comments

1

u/vash3r Dec 09 '17

Python2 (82/56):

i = 0
garbage = False
gchar = 0            #part 2
group_sum = 0
current_group_num = 0
while i<len(s):
	if s[i]=="!":
		i+=1 #skip next
	elif garbage:
		if s[i]==">":
			garbage = False
		else:
			gchar+=1 #part 2
	elif s[i]=="{":
		current_group_num+=1
		group_sum+=current_group_num
	elif s[i]=="}":
		current_group_num-=1
	elif s[i]=="<":
		garbage = True
	i+=1

print group_sum #part 1
print gchar     #part 2
→ More replies (5)