12 lines
346 B
Haskell
12 lines
346 B
Haskell
|
import Data.List (sort, transpose)
|
||
|
import Data.List.Split (splitOn)
|
||
|
|
||
|
solve :: [[Int]] -> Int
|
||
|
solve = sum . map abs . (\[x, xx] -> zipWith (-) x xx) . map sort
|
||
|
|
||
|
main :: IO ()
|
||
|
main =
|
||
|
print . solve . transpose . map parseLine . lines =<< readFile "data.txt"
|
||
|
where
|
||
|
parseLine = map read . filter (not . null) . splitOn " "
|