diff options
Diffstat (limited to 'execs')
-rw-r--r-- | execs/Day13.hs | 25 |
1 files changed, 25 insertions, 0 deletions
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 @@ | |||
1 | module Main where | ||
2 | |||
3 | import Utils | ||
4 | import Data.List.Split | ||
5 | import Data.Tuple | ||
6 | import Data.List (sortOn) | ||
7 | import Data.Bifunctor | ||
8 | import Control.Monad (zipWithM, ap) | ||
9 | |||
10 | earliest :: Int -> [Int] -> Int | ||
11 | earliest start ls = t * b | ||
12 | where (t, b) = minimum $ map swap $ zip `ap` map (mod start) $ ls | ||
13 | |||
14 | gold :: [(Int, Int)] -> Int | ||
15 | gold ls = t | ||
16 | where Just t = chineseRemainder ls | ||
17 | |||
18 | main :: IO () | ||
19 | main = do | ||
20 | n <- lines <$> readFile "input/13" | ||
21 | let start = read (head n) :: Int | ||
22 | departs = map read $ filter (/= "x") $ splitOn "," (last n) | ||
23 | offs = map (bimap negate read) $ filter ((/= "x") . snd) $ zip [0..] $ splitOn "," (last n) | ||
24 | print $ earliest (negate start) departs | ||
25 | print $ gold offs | ||