From 9c415c44ccfba2b1ec502f4d00c4a7afe074aca1 Mon Sep 17 00:00:00 2001 From: pingu Date: Sun, 1 Dec 2024 15:58:01 +0100 Subject: [PATCH] A bit more clean --- app/1.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/1.hs b/app/1.hs index e62d9c6..5b57b50 100644 --- a/app/1.hs +++ b/app/1.hs @@ -15,15 +15,14 @@ parse = unzip . [a,b] -> (read a, read b) e -> error $ "Parsing failed on: " ++ show e ) <$>) . - (filter (/= mempty) <$>) . - (splitWhen isSpace <$>) . + (filter (/= mempty) . splitWhen isSpace <$>) . lines 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 +solve2 (as,bs) = foldr (\a -> (a * length (filter (==a) bs) +)) 0 as main :: IO () main = readFile "inputs/1" <&> parse >>= \i ->