A bit more clean
This commit is contained in:
parent
0eecc96a38
commit
9c415c44cc
5
app/1.hs
5
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 ->
|
||||
|
Loading…
Reference in New Issue
Block a user