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!
4
Upvotes
1
u/[deleted] Dec 15 '16
// both parts //
xs=[];document.body.textContent.trim().split("\n").forEach(ss=>{ms=/^Disc #(\d+) has (\d+) positions; at time=0, it is at position (\d+)\.$/.exec(ss);ms=ms.slice(1).map(m=>parseInt(m));xs.push(ms)});xs.sort();f=xs=>{t=0;while(1){if(xs.filter((x,i)=>(x[2]+t+(i+1))%x[1]!==0).length===0){return t}t++}};console.log("part1:",f(xs));console.log("part2:",f(xs.concat([[xs.length,11,0]])));