31 lines
753 B
Haskell
31 lines
753 B
Haskell
{-# LANGUAGE LambdaCase #-}
|
|
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
|
|
{-# HLINT ignore "Redundant <&>" #-}
|
|
module Main where
|
|
|
|
import Data.Functor
|
|
import Data.List.Split
|
|
import Data.Char
|
|
import Data.Function
|
|
import Data.List
|
|
|
|
parse :: String -> ([Int], [Int])
|
|
parse = unzip .
|
|
((\case
|
|
[a,b] -> (read a, read b)
|
|
e -> error $ "Parsing failed on: " ++ show e
|
|
) <$>) .
|
|
(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 -> (a * length (filter (==a) bs) +)) 0 as
|
|
|
|
main :: IO ()
|
|
main = readFile "inputs/1" <&> parse >>= \i ->
|
|
print (solve1 i) >>
|
|
print (solve2 i)
|