summaryrefslogtreecommitdiff
path: root/2020/3.hs
blob: 20fe0ec7d94861dddec83b6b6436f51e17e62929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Main where

import qualified Data.Array as A

import Input


main :: IO ()
main = do
    input <- getInput 3
    let height = length input
        width = length (head input)

    let grid = A.array ((0, 0), (height - 1, width - 1))
                    [((y, x), fromEnum (c == '#'))
                    | (y, row) <- zip [0..] input
                    , (x, c) <- zip [0..] row]

        countSlope hor ver =
            let nsteps = height `div` ver
            in sum [grid A.! (ver * i, hor * i `mod` width) | i <- [0..nsteps-1]]

    print (countSlope 3 1)

    print (product (map (uncurry countSlope) [(1,1), (3,1), (5,1), (7,1), (1,2)]))