[hs] Solve 2020_01

This commit is contained in:
Joscha 2020-12-01 23:09:25 +00:00
parent a8a35f3289
commit 17379cc287
3 changed files with 39 additions and 0 deletions

32
hs/src/Aoc/Y2020/A01.hs Normal file
View file

@ -0,0 +1,32 @@
module Aoc.Y2020.A01
( solve202001
) where
import Control.Monad
findPair :: [Integer] -> (Integer, Integer)
findPair l = head $ do
a <- l
b <- l
guard $ a + b == 2020
pure (a, b)
findTriple :: [Integer] -> (Integer, Integer, Integer)
findTriple l = head $ do
a <- l
b <- l
c <- l
guard $ a + b + c == 2020
pure (a, b, c)
solve202001 :: FilePath -> IO ()
solve202001 f = do
values <- map read . lines <$> readFile f
putStrLn ">> Part 1"
let (x1, x2) = findPair values
putStrLn $ show x1 ++ " * " ++ show x2 ++ " = " ++ show (x1 * x2)
let (y1, y2, y3) = findTriple values
putStrLn ">> Part 2"
putStrLn $ show y1 ++ " * " ++ show y2 ++ " * " ++ show y3 ++ " = " ++ show (y1 * y2 * y3)