Day 2 appears to be a parsing problem. So given
forward 5 down 5 forward 8 up 3 down 8 forward 2
We want to increment the X co-ordinate when going forwards and either increment the Y co-ordinate when going up or down.
To solve this, I am first going to map my strings into tuples representing the change in X or Y. So down 5 gets translated into (0, -5). I am also going to create a monoid under sum and fold over my tuple array to get my final change in X and Y.
-- Part 2
This introduces an aim concept. To solve this, I am re-using the tuple mapping from part 1 and I will need a reducing function that takes in a current [horizontal, depth, aim] and a [forward, updown] tuple and produces a new [horizontal', depth', aim'] tuple.
Top comments (0)