id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

 

dvr_remote


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 right infrared signals to the DVR to move the cursor. In this exercise you won't write the whole app, but you will write a function to convert a title into a sequence of characters representing the button pushes. dvr_remote(title, width) converts title into button presses, assuming a grid that is 'width' characters wide. That is, if width is, say, 5, then the top row of letters is "A B C D E", the second row is "F G H I J", and so on, until the final row is "Z" followed by a space character. The button presses will be represented by "U", "D", "L", "R" for up, down, left, and right, and by "@" for the select key. The cursor always starts under the "A" at the upper left. For example, with width 5 letters, the movie "UP" would be "DDDD@U@". The "U" of "UP" is the first character in the fifth row, so we start with four down arrows, "DDDD", then the "@" to select the "U". The "P" character is right above the the "U", so we need an up arrow followed by a selection, "U@", to complete the movie selection. You may assume that every title will consist only of letters and space characters.


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@'

...Save, Compile, Run (ctrl-enter)

def dvr_remote(title, width):

Editor font size %:
Shorter output


Forget It! -- delete my code for this problem

Progress graphs:
 Your progress graph for this problem
 Random user progress graph for this problem
 Random Epic Progress Graph

Python Help

Difficulty: 212 Post-solution available

Copyright Nick Parlante 2017 - privacy