Created
December 2, 2016 14:29
-
-
Save ztane/76ffc7e89d76c72f4ecf6b91c9b21183 to your computer and use it in GitHub Desktop.
AoC day 2 part 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aoc import * | |
keyboard = """ | |
xx1xx | |
x234x | |
56789 | |
xABCx | |
xxDxx | |
""".split() | |
x, y = 2, 2 | |
directions = { | |
'U': (0, -1), | |
'D': (0, 1), | |
'L': (-1, 0), | |
'R': (1, 0) | |
} | |
seq = '' | |
for line in input_lines(): | |
for i in line: | |
dx, dy = directions[i] | |
new_x = clamp(x + dx, 0, 4) | |
new_y = clamp(y + dy, 0, 4) | |
if keyboard[new_y][new_x] != 'x': | |
x, y = new_x, new_y | |
seq += keyboard[y][x] | |
print(seq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment