chore: simplify day 1, part 1
This commit is contained in:
parent
f88701078a
commit
70977dad81
1 changed files with 6 additions and 14 deletions
|
@ -3,22 +3,14 @@
|
||||||
import Data.List
|
import Data.List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
main :: IO ()
|
main = interact findSolution
|
||||||
main =
|
|
||||||
do
|
|
||||||
input <- getInput
|
|
||||||
|
|
||||||
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]
|
pairs = sequence . replicate 2
|
||||||
getInput = fmap (map read . lines) getContents
|
|
||||||
|
|
||||||
pairs :: [a] -> [(a, a)]
|
isSolutionPair = (2020 ==) . sum
|
||||||
pairs [] = []
|
|
||||||
pairs [_] = []
|
|
||||||
pairs (x:xs) = [(x, y) | y <- xs] ++ pairs xs
|
|
||||||
|
|
||||||
isSolutionPair :: (Int, Int) -> Bool
|
findJust f = fromJust . find f
|
||||||
isSolutionPair (a, b) = a + b == 2020
|
|
||||||
|
|
Loading…
Reference in a new issue