Skip to content

Commit d5c3ca7

Browse files
authored
Merge pull request #2 from unstko/adventofcode2016-1
adventofcode2016-1 Day 2 - Part 1: Wrong solution 47968
2 parents c04ff30 + f7dfb04 commit d5c3ca7

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

02/log.txt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,27 @@ Continuing from "9", you move left, up, right, down, and left, ending with 8.
2323
Finally, you move up four times (stopping at "2"), then down once, ending with 5.
2424
So, in this example, the bathroom code is 1985.
2525

26-
Your puzzle input is the instructions from the document you found at the front desk. What is the bathroom code?
26+
Your puzzle input is the instructions from the document you found at the front desk. What is the bathroom code?
27+
28+
Your puzzle answer was 47978.
29+
30+
The first half of this puzzle is complete! It provides one gold star: *
31+
32+
--- Part Two ---
33+
34+
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:
35+
36+
1
37+
2 3 4
38+
5 6 7 8 9
39+
A B C
40+
D
41+
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:
42+
43+
You start at "5" and don't move at all (up and left are both edges), ending at 5.
44+
Continuing from "5", you move right twice and down three times (through "6", "7", "B", "D", "D"), ending at D.
45+
Then, from "D", you move five more times (through "D", "B", "C", "C", "B"), ending at B.
46+
Finally, after five more moves, you end at 3.
47+
So, given the actual keypad layout, the code would be 5DB3.
48+
49+
Using the same instructions in your puzzle input, what is the correct bathroom code?

lib/keypad.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ def move(self, direction):
1010
elif direction == 'D':
1111
button = self.button + 3
1212
elif direction == 'L':
13-
button = self.button - 1
13+
if self.button not in (4, 7):
14+
button = self.button - 1
1415
elif direction == 'R':
15-
button = self.button + 1
16+
if self.button not in (3, 6):
17+
button = self.button + 1
1618
if 0 < button < 10:
1719
self.button = button
1820

0 commit comments

Comments
 (0)