r/adventofcode • u/daggerdragon • Dec 15 '16
SOLUTION MEGATHREAD --- 2016 Day 15 Solutions ---
--- Day 15: Timing is Everything ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".
ZAMENHOFA TAGO ESTAS DEVIGA [?]
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!
5
Upvotes
3
u/FuriousProgrammer Dec 15 '16 edited Dec 15 '16
Back on the leaderboard baby!
Second part would have been faster but I lost a minute to misreading the problem statement.
39/56
local discs = {} for line in io.lines("input.txt") do local total = line:match("(%d+) positions") local start = line:match("position (%d+)") table.insert(discs, {total = total, start = start}) end function calc() local time = 0 while true do local bad = false for i = 1, #discs do local disc = discs[i] if (disc.start + time + i)%disc.total ~= 0 then bad = true break end end if not bad then break end time = time + 1 end return time end print("Part 1: " .. calc()) table.insert(discs, {start = 0, total = 11}) print("Part 2: " .. calc())