From 6b4d4466aee35bd748f252a3612054ce70a190e2 Mon Sep 17 00:00:00 2001 From: Xiretza Date: Wed, 2 Dec 2020 10:12:00 +0100 Subject: [PATCH] 2020 day1/haskell: add solution --- 2020/day1/day1.hs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 2020/day1/day1.hs diff --git a/2020/day1/day1.hs b/2020/day1/day1.hs new file mode 100644 index 0000000..643ff82 --- /dev/null +++ b/2020/day1/day1.hs @@ -0,0 +1,12 @@ +{-# LANGUAGE TypeApplications #-} + +import Data.List +import Data.Maybe +import Control.Monad + +find_n_summing :: (Num a, Eq a) => a -> Int -> [a] -> Maybe [a] +find_n_summing to = (find ((to ==) . sum) .) . replicateM + +main = do + nums <- fmap read <$> lines <$> readFile "input.txt" + mapM_ print $ product <$> fromJust <$> flip (find_n_summing 2020) nums <$> [2, 3]