-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdvent2016_02b.py
38 lines (33 loc) · 1.03 KB
/
Advent2016_02b.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/python3
import sys
keyMap = {(0, 0): " ", (1, 0): " ", (2, 0): "1", (3, 0): " ", (4, 0): " ",
(0, 1): " ", (1, 1): "2", (2, 1): "3", (3, 1): "4", (4, 1): " ",
(0, 2): "5", (1, 2): "6", (2, 2): "7", (3, 2): "8", (4, 2): "9",
(0, 3): " ", (1, 3): "A", (2, 3): "B", (3, 3): "C", (4, 3): " ",
(0, 4): " ", (1, 4): " ", (2, 4): "D", (3, 4): " ", (4, 4): " "}
x = 0
y = 2
tempx = 0
tempy = 0
passcode = ""
while True:
string = sys.stdin.readline()
if len(string) > 1:
for direction in string:
tempx = x
tempy = y
if direction == "U":
tempy = max(y-1, 0)
elif direction == "D":
tempy = min(y+1, 4)
elif direction == "L":
tempx = max(x-1, 0)
elif direction == "R":
tempx = min(x+1, 4)
if keyMap[(tempx, tempy)] != " ":
x = tempx
y = tempy
passcode += keyMap[(x, y)]
else:
break
print passcode