Skip to main content
2 of 4
Updated challenge timeframe
Tas
  • 613
  • 6
  • 15

Enter your name via a D-pad

The puzzle:

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*:

Default:

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 up, down, left and right)

The screen also typically let you move from one side directly to the other. That is, if you were focussed on the letter J, pressing right would allow you to move to the letter A.

Whenever I was entering my name, I'd always try to work out the quickest way to do so.

#Goal: 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.

#Considerations: You do not need to include the key pressed for pressing the actual character.
Focus always starts at the A
Enter = must be pressed at the end

Example:

input: Code Golf
output: 44

Explained:
A -> C = 3
C -> ^ = 6 (moving to the left)
^ -> o = 5
o -> d = 2
d -> e = 1
e -> + = 5
+ -> _ = 1
_ -> + = 1
+ -> G = 3
G -> o = 3
o -> l = 3
l -> f = 5
f -> = = 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.

Tas
  • 613
  • 6
  • 15