20 lines
385 B
Haskell
20 lines
385 B
Haskell
|
import Control.Arrow
|
||
|
|
||
|
main :: IO ()
|
||
|
main = do
|
||
|
input <- parse <$> readFile "input"
|
||
|
print $ day09 input
|
||
|
|
||
|
parse :: String -> [[Int]]
|
||
|
parse = map (map read . words) . lines
|
||
|
|
||
|
day09 :: [[Int]] -> (Int, Int)
|
||
|
day09 =
|
||
|
(sum *** sum) .
|
||
|
unzip .
|
||
|
map
|
||
|
((f (+) last &&& f (-) head) .
|
||
|
takeWhile (not . null) . iterate (zipWith (-) =<< tail))
|
||
|
where
|
||
|
f f1 f2 = foldr1 f1 . map f2
|