aboutsummaryrefslogtreecommitdiff
path: root/execs/Day09.hs
diff options
context:
space:
mode:
Diffstat (limited to 'execs/Day09.hs')
-rw-r--r--execs/Day09.hs10
1 files changed, 5 insertions, 5 deletions
diff --git a/execs/Day09.hs b/execs/Day09.hs
index f1c41f2..7bf4908 100644
--- a/execs/Day09.hs
+++ b/execs/Day09.hs
@@ -1,9 +1,9 @@
1 1
2module Main where 2module Main where
3 3
4import Utils 4import Data.Bifunctor
5import Data.List (inits, tails, find, sort) 5import Data.List (find, inits, sort, tails)
6import Data.Bifunctor 6import Utils
7 7
8parseLine :: String -> Int 8parseLine :: String -> Int
9parseLine = read 9parseLine = read
@@ -13,12 +13,12 @@ doCheck preamble target = target `elem` p
13 where p = [x + y | x <- preamble, y <- preamble, x /= y] 13 where p = [x + y | x <- preamble, y <- preamble, x /= y]
14 14
15checkAll :: [[Int]] -> [Int] -> [(Int, Bool)] 15checkAll :: [[Int]] -> [Int] -> [(Int, Bool)]
16checkAll = zipWith (\p t -> (t, doCheck p t)) 16checkAll = zipWith (\p t -> (t, doCheck p t))
17 17
18findWeakness :: [[Int]] -> Int -> Int 18findWeakness :: [[Int]] -> Int -> Int
19findWeakness subs target = minimum t + maximum t 19findWeakness subs target = minimum t + maximum t
20 where Just t = find ((== target) . sum) subs 20 where Just t = find ((== target) . sum) subs
21 21
22main :: IO () 22main :: IO ()
23main = do 23main = do
24 n <- map parseLine . lines <$> readFile "input/09" 24 n <- map parseLine . lines <$> readFile "input/09"