Safe Haskell | None |
---|
Day03
Description
General - (AFAI can see) Hamler does not support streams/lazy lists (yet). Means for this one I will not use a data structure based approach, but will compute the solution :).
For that we will read the input and will build and array of lines that have the tree positions on it (let's call it a forrest).
I can then go into that forrest with my current position (x, y) and can check, if I am hitting a tree. Note: y needs to be modolo the line length.
Then I am repeating this n times (the number of lines in the input file) advancing m steps (3) to the right until I am done (and count the number of trees I am hitting on the way).
Part 1 - Doing the above.
Part 2 - Using part1 to do it for all given moves.
Synopsis
- type Coordinates = (Int, Int)
- type Trees = [Coordinates]
- data Forrest = Forrest Int Int Trees
- input :: String -> Forrest
- part1 :: Forrest -> Coordinates -> Int
- part2 :: Forrest -> Int
Documentation
type Coordinates = (Int, Int) #
type Trees = [Coordinates] #
The forrest with all its trees.
part1 :: Forrest -> Coordinates -> Int #
Solve part1.