Last active
December 18, 2015 13:19
-
-
Save thisiswei/5789491 to your computer and use it in GitHub Desktop.
You know how the remote on your DVR makes you select the title of a movie or TV show by moving a cursor up/down/left/right through a grid of letters and then pressing the 'select' key? It takes forever and is very annoying. Imagine you had an app running on your phone that would allow you to type or speak the name, and the app would send the rig…
This file contains hidden or 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
def dvr_remote(s, width): | |
x = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' | |
rows = [x[i:i+width] for i in range(0, 27, width)] | |
s = 'A' + s.replace(' ', '_') | |
DIC = dict((char, (i, pos)) | |
for i in range(len(rows)) | |
for (pos, char) in enumerate(rows[i])) | |
def helper(current, next): | |
row1, col1 = DIC[current] | |
row2, col2 = DIC[next] | |
LR = "" if col1 == col2 else (abs(col1-col2) * 'RL'[col1>col2]) | |
UD = "" if row1 == row2 else (abs(row1-row2) * 'DU'[row1>row2]) | |
return LR + UD + '@' | |
return ''.join(helper(s[i], s[i+1]) for i in range(len(s)-1)) | |
how to code this in haskell?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dvr_remote('UP', 5) → 'DDDD@U@'
dvr_remote('JAWS', 5) → 'RRRRD@LLLLU@RRDDDD@RU@'
dvr_remote('DAS BOOT', 6) → 'RRR@LLL@DDD@RRD@LUUUU@RDD@@ld@'