Merge AoC 2019 & 2020 Haskell codebases

This commit is contained in:
Xavier Morel
2020-12-03 10:22:16 +01:00
parent 06a86e9d37
commit a04451f2f7
57 changed files with 364 additions and 688 deletions

View File

@@ -0,0 +1,22 @@
module Y2020.Day03 (y20day03) where
walkMap :: (Int, Int) -> (Int, Int) -> [(Int, Int)]
walkMap (w, h) (wstep, hstep) = zip wCoords hCoords
where wCoords = map (`mod` w) $ take h $ iterate (+ wstep) 0
hCoords = take h $ iterate (+ hstep) 0
getCharAtPos :: [String] -> (Int, Int) -> Char
getCharAtPos myMap (w, h)
| h <= length myMap = (myMap !! h) !! w
| otherwise = '\0'
getNumberOfTrees :: [String] -> [(Int, Int)] -> Int
getNumberOfTrees myMap coords = length $ filter (== '#') $ map (getCharAtPos myMap) coords
y20day03 :: [String] -> (String, String)
y20day03 input = (part1, part2)
where width = length $ input !! 0
height = (length $ input)
getNb slope = getNumberOfTrees input $ walkMap (width, height) slope
part1 = show $ getNb (3, 1)
part2 = show $ product $ map getNb [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)]