Part 1
In this puzzle, we are given a keypad and a list of moves on this keypad. We are asked to find the button after the moves are executed.
To simplify the border handlind later on, we pad the keypad with special characters indicating a invalid button (I chose a space). We save the current position as a tuple of row / column coordinates. For each move in the list, we check to direction and modifiy our position accordingly. If we move onto an invalid button, we revert this move. The answer is obtained by adding all the buttons after finishing the moves.
Part 2
Part 2 swaps out the keypad from part 1 for a more complicated layout.
After changing the keypad into the new layout and again padding it with space character, part 2 can be solved by the same method as above.
No comments:
Post a Comment