[Python/2016] Move solutions into .py files
This commit is contained in:
parent
0269ad8fc3
commit
2514b1d11f
50 changed files with 1172 additions and 3386 deletions
50
Python/2016/02.py
Normal file
50
Python/2016/02.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
from lib import *
|
||||
|
||||
input = read_input(2016, 2)
|
||||
|
||||
out = []
|
||||
x = y = 1
|
||||
for line in input.splitlines():
|
||||
for c in line:
|
||||
if c == "L" and x > 0:
|
||||
x -= 1
|
||||
|
||||
elif c == "R" and x < 2:
|
||||
x += 1
|
||||
|
||||
elif c == "U" and y > 0:
|
||||
y -= 1
|
||||
|
||||
elif c == "D" and y < 2:
|
||||
y += 1
|
||||
|
||||
out.append(y * 3 + x + 1)
|
||||
|
||||
print(*out, sep="")
|
||||
|
||||
|
||||
out = ""
|
||||
x, y = 0, 2
|
||||
keypad = [" 1 ", " 234 ", "56789", " ABC ", " D "]
|
||||
for line in input.splitlines():
|
||||
for c in line:
|
||||
nx, ny = x, y
|
||||
|
||||
if c == "L":
|
||||
nx -= 1
|
||||
|
||||
elif c == "R":
|
||||
nx += 1
|
||||
|
||||
elif c == "U":
|
||||
ny -= 1
|
||||
|
||||
elif c == "D":
|
||||
ny += 1
|
||||
|
||||
if 0 <= nx < 5 and 0 <= ny < 5 and keypad[ny][nx] != " ":
|
||||
x, y = nx, ny
|
||||
|
||||
out += keypad[y][x]
|
||||
|
||||
print(out)
|
Loading…
Add table
Add a link
Reference in a new issue