aboutsummaryrefslogtreecommitdiff
path: root/execs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-12-13 06:35:25 +0000
committerAkshay <[email protected]>2020-12-13 06:35:25 +0000
commita961cfecaf9c21f41dfabe8d105512326b5881e0 (patch)
tree4c234f5f64190984bf9fd67b42e247bce95bb8ba /execs
parente3d58e974a07b39922696697f23727c6ae333d04 (diff)
add day13, crt from rosetta
Diffstat (limited to 'execs')
-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