Skip to content

Instantly share code, notes, and snippets.

@reikoNeko
Created December 11, 2016 04:35
Show Gist options
  • Save reikoNeko/a51f4c87e85b201495ad3954be8bf33f to your computer and use it in GitHub Desktop.
Save reikoNeko/a51f4c87e85b201495ad3954be8bf33f to your computer and use it in GitHub Desktop.
# In[17]:
keypad=[[1,2,3],[4,5,6],[7,8,9]]
def kp_move(position,ditherings):
r,c = position
#print(ditherings[:3],ditherings[-3:])
for char in ditherings:
if 'U' == char:
r = max(0, r-1)
elif 'D' == char:
r = min(2, r+1)
elif 'R' == char:
c = min(2, r+1)
elif 'L' == char:
c = max(0, c-1)
else:
next
return(r,c)
def shownum(position):
r,c = position
return(keypad[r][c])
# In[18]:
press=[(1,1)] # Start on the 5
with open('input02.txt') as F:
for line in F.readlines():
nextnum = kp_move(press[-1],line.strip())
press.append(nextnum)
# In[19]:
# Part One: Print the bathroom code
for x in press[1:]:
print(shownum(x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment