DEV Community

Discussion on: Advent of Code 2020 Solution Megathread - Day 3: Toboggan Trajectory

Collapse
 
justinh11235 profile image
Justin Hinckley

Here's my beginner's Haskell solution:

ans1 :: [String] -> Int -> Int -> Int
ans1 inp right down = length $ filter (\(ind, row) -> ind `mod` down == 0 && row !! (ind `div` down * right `mod` length row) == '#') $ zip [0..] inp

ans2 :: [String] -> [(Int, Int)] -> Int
ans2 inp = product . map (uncurry (ans1 inp))

main :: IO ()
main = do
    contents <- readFile "adventofcode3.input"

    print $ ans1 (lines contents) 3 1
    print $ ans2 (lines contents) [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]
Enter fullscreen mode Exit fullscreen mode