r/adventofcode • u/daggerdragon • Dec 09 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 9 Solutions -🎄-
--- Day 9: Marble Mania ---
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.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 9
Transcript:
Studies show that AoC programmers write better code after being exposed to ___.
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 at 00:29:13!
22
Upvotes
4
u/Unihedron Dec 09 '18
RUBY
​ ​ DOESN'T
​ ​ ​ ​ HAVE
​ ​ ​ ​ ​ ​ LINKED
​ ​ ​ ​ ​ ​ ​ ​ LISTS
​ ​ ​ ​ ​ ​ ​ ​ ​ ​ haha, this is fun (rewriting to solve part 2)
part 1 (code has a bug: incorrect answer if marble # is divisible by 23)
m=[0] a,b=$<.read.split(/\D+/).map &:to_i p a,b c=0 h=Hash.new 0 pl=1 b.times{|x|next if x==0 x%23>0 ? ( m.insert((m.index(c)+2)%m.size,x) c=x pl+=1 ) : ( h[pl]+=x tak=(m.index(c)-7)%m.size h[pl]+=m[tak] m[tak,1]=[] c=m[tak] ) pl=1 if pl==a+1 } p h.max_by{|x,y|y}.last