aboutsummaryrefslogtreecommitdiff
path: root/execs/Day13.hs
blob: 07d379d8643f14e0ce9c598ca2fd9e1aafd69b91 (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 Utils
import Data.List.Split
import Data.Tuple
import Data.List (sortOn)
import Data.Bifunctor
import Control.Monad (zipWithM, ap)

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