module Main where main :: IO () main = do raw <- readFile "day1.txt" let ls = map read $ lines raw :: [Integer] in do case (solveA ls) of Nothing -> error "no answer" (Just x) -> putStrLn $ "day1a: " ++ (show x) case (solveB ls) of Nothing -> error "no answer" (Just x) -> putStrLn $ "day1b: " ++ (show x) solveA :: [Integer] -> Maybe Integer solveA [] = Nothing solveA xs = Just $ (\(x,y) -> x * y) lsa where lsa = head [ (x,y) | x <- xs, y <- xs, x + y == 2020 ] solveB :: [Integer] -> Maybe Integer solveB [] = Nothing solveB xs = Just $ (\(x,y,z) -> x * y * z) lsb where lsb = head [ (x,y,z) | x <- xs, y <- xs, z <- xs, x + y + z == 2020 ]