From ec5353f4018c7e1ad56d521e38ec06af8d938d97 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Tue, 1 Dec 2020 12:02:17 +0100 Subject: Start of 2020 --- 2020/1.hs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2020/1.hs (limited to '2020/1.hs') diff --git a/2020/1.hs b/2020/1.hs new file mode 100644 index 0000000..c7e9d02 --- /dev/null +++ b/2020/1.hs @@ -0,0 +1,19 @@ +module Main where + +import Data.List (find) +import Data.Maybe (fromJust) +import qualified Data.Set as Set + +import Input + + +main :: IO () +main = do + input <- map read <$> getInput 1 :: IO [Int] + + let num1 = fromJust (find ((`Set.member` Set.fromList input) . (2020 -)) input) + print (num1 * (2020 - num1)) + + let pair = snd (fromJust (find ((`Set.member` Set.fromList input) . (2020 -) . fst) + [(a + b, (a, b)) | a <- input, b <- input])) + print (fst pair * snd pair * (2020 - fst pair - snd pair)) -- cgit v1.2.3-54-g00ecf