aboutsummaryrefslogtreecommitdiff
path: root/execs/Day03.hs
blob: a000e597258bcc00924488049b5211f9612d8905 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 . (== '#')