2020 day1/haskell: add solution

This commit is contained in:
Xiretza 2020-12-02 10:12:00 +01:00
parent d447a9705c
commit 6b4d4466ae

12
2020/day1/day1.hs Normal file
View file

@ -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]