From a961cfecaf9c21f41dfabe8d105512326b5881e0 Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 13 Dec 2020 12:05:25 +0530 Subject: add day13, crt from rosetta --- execs/Day13.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 execs/Day13.hs (limited to 'execs') diff --git a/execs/Day13.hs b/execs/Day13.hs new file mode 100644 index 0000000..07d379d --- /dev/null +++ b/execs/Day13.hs @@ -0,0 +1,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 -- cgit v1.2.3