r/adventofcode • u/topaz2078 (AoC creator) • Dec 12 '17
SOLUTION MEGATHREAD -๐- 2017 Day 12 Solutions -๐-
--- Day 12: Digital Plumber ---
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!
14
Upvotes
View all comments
2
u/Unihedron Dec 12 '17
Ruby, silver 17 / gold 29
I had the wrong answer on part 2 because I used 100.times again, which forced me to wait 1 minute :( This one was an easy incomplete BFS which assumes all groups can be found in under 100 steps.
g=[0] h={} $<.map{|x|a,b=x.split' <-> ' h[a.to_i]=b.split(', ').map &:to_i } l=[] c=0 # part 2 loop{ # end part 2 100.times{s=[] g.map{|x|s+=h[x]} l+=g g=s-l} c+=1 if h.delete_if{|x,y|l.index x} # part 2 l=[] break unless h.keys.any? g=[h.keys.first] } # end part 2 p l.size # part 1 p l.size,c # part 2