You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: day02/README.md
+5Lines changed: 5 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,11 @@ The command typings given in the exercise closely resemble the data type declara
8
8
For debugging purposes, I made my type implement the "Show" class and implemented the "show" method for my type, as shown in this post:
9
9
*[StackOverflow: "Haskell: Deriving Show for custom type"](https://stackoverflow.com/a/6082118/5424404)
10
10
11
+
After having implemented the solutions for both parts, I realized that I could use a folding operation to apply the position changes dictated by the given commands.
12
+
I learned that `foldr` and `foldl` have different results if the combinator function (`applyCommandPartTwo`, in this case) is not associative.
13
+
The combination function's arguments are also flipped:
14
+
*[StackOverflow: "Haskell - foldl and foldr?"](https://stackoverflow.com/a/13280185/5424404)
15
+
11
16
## File structure
12
17
*[`./day02.hs`](./day02.hs): My solution for part one of this puzzle
13
18
*[`./input.txt`](./input.txt): My personal puzzle input for this challenge
Calculates the position (new horizontal position, new depth) if a submarine starting at (horizontal position, depth) follows all of the given commands.
27
+
Calculates the end position (horizontal position, depth) of the submarine when applying the given set of commands
28
+
using the interpretation of part one of the puzzle.
28
29
29
-
>>> calculateEndPosition [Forward 5, Down 5, Forward 8, Up 3, Down 8, Forward 2] (0,0)
30
+
>>> calculateEndPositionPartOne [Forward 5, Down 5, Forward 8, Up 3, Down 8, Forward 2]
0 commit comments