A bit more clean

This commit is contained in:
pingu 2024-12-01 15:58:01 +01:00
parent 0eecc96a38
commit 9c415c44cc

View File

@ -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 ->