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