# Background
My TV remote control has arrow buttons and an `OK` button.
I can use these to move a "cursor" on a logical screen keyboard to type words...
# Keyboard
The screen "keyboard" layout looks like this
  #tvkb {
    width : 400px;
    border: 5px solid gray; border-collapse: collapse;
  }
  #tvkb td {
    color : orange;
    background-color : black;
    text-align : center;
    border: 3px solid gray; border-collapse: collapse;
  }
abcde123
fghij456
klmno789
pqrst.@0
uvwxyz_/
aASP
* `aA` is the SHIFT key. Pressing this key toggles alpha characters between UPPERCASE and lowercase
* `SP` is the space character
* The other blank keys in the bottom row have no function
# Kata task
How many button presses on my remote are required to type the given `words`?
## Hint
This Kata is an extension of the earlier ones in this series. You should complete those first.
## Notes
* The cursor always starts on the letter `a` (top left)
* The alpha characters are initially lowercase (as shown above)
* Remember to also press `OK` to "accept" each letter
* Take the shortest route from one letter to the next
* The cursor wraps, so as it moves off one edge it will reappear on the opposite edge
* Although the blank keys have no function, you may navigate through them if you want to
* Spaces may occur anywhere in the `words` string
* Do not press the SHIFT key until you need to. For example, with the word `e.Z`, the SHIFT change happens **after** the `.` is pressed (not before)
# Example
words = `Code Wars`
* C => `a`-`aA`-OK-`A`-`B`-`C`-OK = 6
* o => `C`-`B`-`A`-`aA`-OK-`u`-`v`-`w`-`x`-`y`-`t`-`o`-OK = 12
* d => `o`-`j`-`e`-`d`-OK = 4
* e => `d`-`e`-OK = 2
* space => `e`-`d`-`c`-`b`-`SP`-OK = 5
* W => `SP`-`aA`-OK-`SP`-`V`-`W`-OK = 6
* a => `W`-`V`-`U`-`aA`-OK-`a`-OK = 6
* r => `a`-`f`-`k`-`p`-`q`-`r`-OK = 6
* s => `r`-`s`-OK = 2
Answer = 6 + 12 + 4 + 2 + 5 + 6 + 6 + 6 + 2 = 49
*Good Luck!
DM.*
Series
* TV Remote
* TV Remote (shift and space)
* TV Remote (wrap)
* TV Remote (symbols)
def tv_remote(word):
    caps, cases, shift = coords["↑"], (str.isupper, str.islower), 0
    moves, current = 0, (0, 0)
    for char in word:
        target = coords[char.lower()]
        if cases[shift](char):
            moves, current, shift = moves + distance(current, caps), caps, 1 - shift
        moves, current = moves + distance(current, target), target
    return moves

keyboard = ("abcde123", "fghij456", "klmno789", "pqrst.@0", "uvwxyz_/", "↑ ")
coords = {char: (line.index(char), y) for y, line in enumerate(keyboard) for char in line}

def distance(pos1, pos2):
    d0, d1 = abs(pos2[0] - pos1[0]), abs(pos2[1] - pos1[1])
    return 1 + min(d0, 8 - d0) + min(d1, 6 - d1)
def tv_remote(word):
    caps, cases, shift = coords["↑"], (str.isupper, str.islower), 0
    moves, current = 0, (0, 0)
    for char in word:
        target = coords[char.lower()]
        if cases[shift](char):
            moves, current, shift = moves + distance(current, caps), caps, 1 - shift
        moves, current = moves + distance(current, target), target
    return moves

keyboard = ("abcde123", "fghij456", "klmno789", "pqrst.@0", "uvwxyz_/", "↑ ")
coords = {char: (line.index(char), y) for y, line in enumerate(keyboard) for char in line}

def distance(pos1, pos2):
    d0, d1 = abs(pos2[0] - pos1[0]), abs(pos2[1] - pos1[1])
    return 1 + min(d0, 8 - d0) + min(d1, 6 - d1)