Puzzle du 2 décembre 2016
This commit is contained in:
parent
379e242297
commit
54c54d264a
|
@ -0,0 +1,31 @@
|
|||
#!/usr/bin/env python3
|
||||
import sys
|
||||
lines = [line.strip() for line in sys.stdin.readlines()]
|
||||
# keypad = ((1, 2, 3), (4, 5, 6), (7, 8, 9))
|
||||
keypad = ((None, None, 1, None, None),
|
||||
(None, 2, 3, 4, None),
|
||||
(5, 6, 7, 8, 9),
|
||||
(None, 'A', 'B', 'C', None),
|
||||
(None, None, 'D', None, None))
|
||||
x, y, code = 0, 2, ""
|
||||
for line in lines:
|
||||
for c in line:
|
||||
if c == 'D':
|
||||
if y + 1 >= len(keypad) or keypad[y + 1][x] is None:
|
||||
continue
|
||||
y = y + 1
|
||||
elif c == 'U':
|
||||
if y - 1 < 0 or keypad[y - 1][x] is None:
|
||||
continue
|
||||
y = y - 1
|
||||
elif c == 'L':
|
||||
if x - 1 < 0 or keypad[y][x - 1] is None:
|
||||
continue
|
||||
x = x - 1
|
||||
elif c == 'R':
|
||||
if x + 1 >= len(keypad[y]) or keypad[y][x + 1] is None:
|
||||
continue
|
||||
x = x + 1
|
||||
code = code + str(keypad[y][x])
|
||||
|
||||
print(code)
|
Loading…
Reference in New Issue