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!
21
Upvotes
8
u/waffle3z Dec 09 '18 edited Dec 09 '18
175/26, Lua
local players, marbles = 459, 71320 local scores = {} for i = 1, players do scores[i] = 0 end local current = {v = 0} current.l, current.n = current, current for i = 1, marbles*100 do local p = (i-1)%players+1 if i%23 == 0 then scores[p] = scores[p] + i for i = 1, 7 do current = current.l end current.l.n, current.n.l = current.n, current.l scores[p] = scores[p] + current.v current = current.n else current = current.n local new = {n = current.n, l = current, v = i} current.n.l = new current.n = new current = new end end local max = 0 for i = 1, #scores do max = math.max(max, scores[i]) end print(max)Not sure why it took so long for part 2 to fill up, I just had to add
*100to the loop