aboutsummaryrefslogtreecommitdiff
path: root/execs/Day13.hs
diff options
context:
space:
mode:
Diffstat (limited to 'execs/Day13.hs')
-rw-r--r--execs/Day13.hs25
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 @@
1module Main where
2
3import Utils
4import Data.List.Split
5import Data.Tuple
6import Data.List (sortOn)
7import Data.Bifunctor
8import Control.Monad (zipWithM, ap)
9
10earliest :: Int -> [Int] -> Int
11earliest start ls = t * b
12 where (t, b) = minimum $ map swap $ zip `ap` map (mod start) $ ls
13
14gold :: [(Int, Int)] -> Int
15gold ls = t
16 where Just t = chineseRemainder ls
17
18main :: IO ()
19main = 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