From ec5c25c4af0ebccaba6c8e807123eb7b39937b9e Mon Sep 17 00:00:00 2001 From: pingu Date: Sun, 1 Dec 2024 11:00:28 +0100 Subject: [PATCH] 1.2 solved --- app/1.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/1.hs b/app/1.hs index 38c1a40..e62d9c6 100644 --- a/app/1.hs +++ b/app/1.hs @@ -22,5 +22,10 @@ parse = unzip . solve1 :: ([Int], [Int]) -> Int solve1 = sum . uncurry (zipWith ((abs .) . (-)) `on` sort) +solve2 :: ([Int], [Int]) -> Int +solve2 (as,bs) = foldr (\a b -> b + a * length (filter (==a) bs)) 0 as + main :: IO () -main = readFile "inputs/1" <&> solve1 . parse >>= print +main = readFile "inputs/1" <&> parse >>= \i -> + print (solve1 i) >> + print (solve2 i)