From 95d2a1392c0de7fb3b71c13baa2174e01695714e Mon Sep 17 00:00:00 2001 From: Sloane Perrault Date: Wed, 21 Sep 2022 09:19:52 -0400 Subject: [PATCH] chore: simplify day 1, part 2 --- 2020/01/part2.hs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/2020/01/part2.hs b/2020/01/part2.hs index 517d836..aa4040b 100755 --- a/2020/01/part2.hs +++ b/2020/01/part2.hs @@ -3,22 +3,14 @@ import Data.List import Data.Maybe -main :: IO () -main = - do - input <- getInput +main = interact findSolution - let answer = product $ fromJust $ find isSolutionTriple $ triples input +findSolution = show . product . findJust isSolutionTriple . triples . parseInput - putStrLn $ show answer +parseInput = map read . lines -getInput :: IO [Int] -getInput = fmap (map read . lines) getContents +triples = sequence . replicate 3 -triples :: [a] -> [[a]] -triples xs = sequence $ replicate 3 xs +isSolutionTriple = (2020 ==) . sum -isSolutionTriple :: [Int] -> Bool -isSolutionTriple triple = sum triple == 2020 - -multplyTriple (a, b, c) = a * b * c +findJust f = fromJust . find f