aboutsummaryrefslogtreecommitdiff
path: root/execs/Day13.hs
blob: ca64fe04bdab7570fba915c2ac6025bf0c63c2fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Main where

import           Control.Monad   (ap, zipWithM)
import           Data.Bifunctor
import           Data.List       (sortOn)
import           Data.List.Split
import           Data.Tuple
import           Utils

earliest :: Int -> [Int] -> Int
earliest start ls = t * b
    where (t, b) = minimum $ map swap $ zip `ap` map (mod start) $ ls

gold :: [(Int, Int)] -> Int
gold ls = t
    where Just t = chineseRemainder ls

main :: IO ()
main = do
    n <- lines <$> readFile "input/13"
    let start   = read (head n) :: Int
        departs = map read $ filter (/= "x") $ splitOn "," (last n)
        offs    = map (bimap negate read) $ filter ((/= "x") . snd) $ zip [0..] $ splitOn "," (last n)
    print $ earliest (negate start) departs
    print $ gold offs