chore: simplify day 1, part 2
This commit is contained in:
parent
70977dad81
commit
95d2a1392c
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 = product $ fromJust $ find isSolutionTriple $ triples input
|
findSolution = show . product . findJust isSolutionTriple . triples . parseInput
|
||||||
|
|
||||||
putStrLn $ show answer
|
parseInput = map read . lines
|
||||||
|
|
||||||
getInput :: IO [Int]
|
triples = sequence . replicate 3
|
||||||
getInput = fmap (map read . lines) getContents
|
|
||||||
|
|
||||||
triples :: [a] -> [[a]]
|
isSolutionTriple = (2020 ==) . sum
|
||||||
triples xs = sequence $ replicate 3 xs
|
|
||||||
|
|
||||||
isSolutionTriple :: [Int] -> Bool
|
findJust f = fromJust . find f
|
||||||
isSolutionTriple triple = sum triple == 2020
|
|
||||||
|
|
||||||
multplyTriple (a, b, c) = a * b * c
|
|
||||||
|
|
Loading…
Reference in a new issue