aboutsummaryrefslogtreecommitdiff
path: root/execs/Day03.hs
diff options
context:
space:
mode:
Diffstat (limited to 'execs/Day03.hs')
-rw-r--r--execs/Day03.hs18
1 files changed, 18 insertions, 0 deletions
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 @@
1module Main where
2
3main :: IO ()
4main = do
5 n <- lines <$> readFile "input/03"
6 print $ countTrees 3 1 n
7 print $ product [ countTrees 1 1 n
8 , countTrees 3 1 n
9 , countTrees 5 1 n
10 , countTrees 7 1 n
11 , countTrees 1 2 n
12 ]
13
14countTrees :: Int -> Int -> [String] -> Int
15countTrees right down ls = go (map cycle ls)
16 where go [] = 0
17 go remaining@(r:rs) = i (head r) + go (map (drop right) (drop down remaining))
18 where i = fromEnum . (== '#')