1.1 solved
This commit is contained in:
26
app/1.hs
Normal file
26
app/1.hs
Normal file
@ -0,0 +1,26 @@
|
||||
{-# 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)
|
||||
|
||||
main :: IO ()
|
||||
main = readFile "inputs/1" <&> solve1 . parse >>= print
|
Reference in New Issue
Block a user