From 6bd6cf1350e96011c08652cdbb1dd39279666715 Mon Sep 17 00:00:00 2001 From: Akshay Date: Thu, 3 Dec 2020 11:23:13 +0530 Subject: add initial day 3 solution --- execs/Day03.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 execs/Day03.hs (limited to 'execs/Day03.hs') diff --git a/execs/Day03.hs b/execs/Day03.hs new file mode 100644 index 0000000..a000e59 --- /dev/null +++ b/execs/Day03.hs @@ -0,0 +1,18 @@ +module Main where + +main :: IO () +main = do + n <- lines <$> readFile "input/03" + print $ countTrees 3 1 n + print $ product [ countTrees 1 1 n + , countTrees 3 1 n + , countTrees 5 1 n + , countTrees 7 1 n + , countTrees 1 2 n + ] + +countTrees :: Int -> Int -> [String] -> Int +countTrees right down ls = go (map cycle ls) + where go [] = 0 + go remaining@(r:rs) = i (head r) + go (map (drop right) (drop down remaining)) + where i = fromEnum . (== '#') -- cgit v1.2.3