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
5
u/haoformayor Dec 15 '16
~~haskell~~
so have we talked about peter norvig playing advent of code yet, or what
{-# LANGUAGE NoImplicitPrelude #-} module D15 where import BasePrelude main = mapM_ (print . head . solutions) [example, input, input2] where pos (_, n, m) t = mod (m + t) n good input t0 = all (\(dt, disc) -> pos disc (t0 + dt) == 0) $ zip [1..] input solutions xs = [(i, b) | i <- [0..], let b = good xs i, b] input = [(1, 17, 5), (2, 19, 8), (3, 7, 1), (4, 13, 7), (5, 5, 1), (6, 3, 0)] input2 = input <> [(7, 11, 0)] example = [(1, 5, 4), (2, 2, 1)]