AoC/2020/day03/day03.hs

24 lines
573 B
Haskell
Raw Normal View History

2020-12-03 06:38:37 +01:00
main :: IO ()
main = do
input <- map (concat . repeat) . lines <$> readFile "input"
2020-12-03 06:47:24 +01:00
print $ day3 input (3,1)
2020-12-03 06:46:38 +01:00
let slopes = [(1,1),(3,1),(5,1),(7,1),(1,2)]
2020-12-03 06:38:37 +01:00
print $ product $ map (day3 input) slopes
type Slope = ((Int, Int), Int)
2020-12-03 06:46:38 +01:00
day3 :: [String] -> (Int,Int) -> Int
2020-12-03 06:38:37 +01:00
day3 input slope = a
where
2020-12-03 06:46:38 +01:00
(_, a) = day3rec (input, 0) (slope,0)
2020-12-03 06:38:37 +01:00
day3rec :: ([String], Int) -> Slope -> ([String], Int)
day3rec (t:ts, acc) ((x, y), l) =
day3rec
( drop y (t : ts)
, if t !! (l * x) == '.'
then acc
else succ acc)
((x, y), succ l)
day3rec x _ = x