Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion 02/log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,27 @@ Continuing from "9", you move left, up, right, down, and left, ending with 8.
Finally, you move up four times (stopping at "2"), then down once, ending with 5.
So, in this example, the bathroom code is 1985.

Your puzzle input is the instructions from the document you found at the front desk. What is the bathroom code?
Your puzzle input is the instructions from the document you found at the front desk. What is the bathroom code?

Your puzzle answer was 47978.

The first half of this puzzle is complete! It provides one gold star: *

--- Part Two ---

You finally arrive at the bathroom (it's a several minute walk from the lobby so visitors can behold the many fancy conference rooms and water coolers on this floor) and go to punch in the code. Much to your bladder's dismay, the keypad is not at all like you imagined it. Instead, you are confronted with the result of hundreds of man-hours of bathroom-keypad-design meetings:

1
2 3 4
5 6 7 8 9
A B C
D
You still start at "5" and stop when you're at an edge, but given the same instructions as above, the outcome is very different:

You start at "5" and don't move at all (up and left are both edges), ending at 5.
Continuing from "5", you move right twice and down three times (through "6", "7", "B", "D", "D"), ending at D.
Then, from "D", you move five more times (through "D", "B", "C", "C", "B"), ending at B.
Finally, after five more moves, you end at 3.
So, given the actual keypad layout, the code would be 5DB3.

Using the same instructions in your puzzle input, what is the correct bathroom code?
6 changes: 4 additions & 2 deletions lib/keypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ def move(self, direction):
elif direction == 'D':
button = self.button + 3
elif direction == 'L':
button = self.button - 1
if self.button not in (4, 7):
button = self.button - 1
elif direction == 'R':
button = self.button + 1
if self.button not in (3, 6):
button = self.button + 1
if 0 < button < 10:
self.button = button

Expand Down