1
0
Fork 0

chore: simplify day 1, part 1

This commit is contained in:
Zach Perrault 2020-12-01 01:55:17 -05:00
parent 11dc9c353d
commit 0c847656e9
No known key found for this signature in database
GPG key ID: D59F59045E12F0F5

View file

@ -3,22 +3,14 @@
import Data.List
import Data.Maybe
main :: IO ()
main =
do
input <- getInput
main = interact findSolution
let answer = uncurry (*) $ fromJust $ find isSolutionPair $ pairs input
findSolution = show . product . findJust isSolutionPair . pairs . parseInput
putStrLn $ show answer
parseInput = map read . lines
getInput :: IO [Int]
getInput = fmap (map read . lines) getContents
pairs = sequence . replicate 2
pairs :: [a] -> [(a, a)]
pairs [] = []
pairs [_] = []
pairs (x:xs) = [(x, y) | y <- xs] ++ pairs xs
isSolutionPair = (2020 ==) . sum
isSolutionPair :: (Int, Int) -> Bool
isSolutionPair (a, b) = a + b == 2020
findJust f = fromJust . find f