Consider a console/hand-held game with a d-pad where you are required to enter a name of sorts. This appeared in many older games before the use of QWERTY was popularised in consoles (e.g. I believe the Wii uses a QWERTY keyboard layout for input). Typically, the on-screen keyboard looks to the effect of*:
0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z _ + ^ =
With the case switched:
0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z - + ^ =
That is, all alphanumeric keys and the following:
_: A single space
-: A hyphen
+: Switch case for the next letter only
^: Toggle caps lock (that is, switch the case of all letters)
=: Enter, complete
*Obviously I replaced keys like "BKSP" and "ENTER" with shorter versions
And then the hardware would include a d-pad (or some form of control where you could go
The screen also typically let you move from one side directly to the other. That is, if you were focussed on the letter
right would allow you to move to the letter
Whenever I was entering my name, I'd always try to work out the quickest way to do so.
Your program will take string input which may include any alphanumeric character including a space and hyphen, and your goal is to output the shortest amount of key presses on the d-pad to output the required string.
You do not need to include the key pressed for pressing the actual character.
Focus always starts at the
= must be pressed at the end
input: Code Golf
C = 2
^ = 6 (moving to the left)
o = 5
d = 2
e = 1
+ = 5
_ = 1
+ = 1
G = 3
o = 3
l = 3
f = 5
= = 6
Note that it is quicker to hit the
+ twice for a
_ and a
G than it is to hit
^ once, then swap back.
The winning submission (I'll allow at least 1w) will be the shortest solution (in bytes). As this is my first question, I hope this is clear and not too hard.