Skip to content

Instantly share code, notes, and snippets.

@ztane
Created December 2, 2016 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ztane/76ffc7e89d76c72f4ecf6b91c9b21183 to your computer and use it in GitHub Desktop.
Save ztane/76ffc7e89d76c72f4ecf6b91c9b21183 to your computer and use it in GitHub Desktop.
AoC day 2 part 2
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