Efficient Typing on a Game Boy
JavaScript (ES6), 147 bytes
s=>s.replace(/./g,c=>(q=p,p="AHOVBIPWCJQXDKRYELSZFMY.GNU ".indexOf(c),"<<<>>>".substring(3,((p>>2)+10-(q>>2))%7)+["","v","vv","^"][p-q&3]+"."),p=0)
An interesting behaviour of substring
is that it exchanges the arguments if the second is less than the first. This means that if I calculate the optimal number of left/right presses as a number between -3 and 3, I can add 3, and take the substring of <<<>>>
starting at 3 and I will get the correct number of arrows. Meanwhile the down/up presses are simply handled by looking up an array using a bitwise and of the difference in rows with 3; this way is slightly shorter as there are fewer array elements.
Dyalog APL, 61 bytes
4 7∘{∊'.',⍨⍉↑b⍴¨¨'^v' '<>'⌷¨⍨⊂¨a>b←a⌊⍺-a←⍺|↓2-/0,⍺⊤⍵⍳⍨⎕a,'.'}
assumes ⎕IO←0
⎕a,'.'
the alphabet followed by a full stop
⍵⍳⍨
find the argument's chars there as indices 0..26 (' '
and all others will be 27)
⍺⊤
encode in base 7 (note the left arg ⍺
is bound to 4 7
), get a 2×n matrix
0,
prepend zeros to the left
2-/
differences between adjacent columns
↓
split the matrix into a pair of vectors
a←⍺|
take them modulo 4 and 7 respectively, assign to a
b←a⌊⍺-a
make b
the smaller of a
and its modular inverse
'^v' '<>'⌷¨⍨⊂¨a>b
choose ^
or v
for the first vector and <
or >
for the second, based on where a
differs from b
b⍴¨¨
repeat each of those b
times
⍉↑
mix the two vectors into a single matrix and transpose it, get an n×2 matrix
'.',⍨
append .
-s on the right
∊
flatten
Ruby, 107 bytes
->s{c=0
s.tr(". ","[\\").bytes{|b|b-=65
print ["","^","^^","v"][c/7-b/7],(d=(c-c=b)%7)>3??>*(7-d):?<*d,?.}}
Ungolfed in test program
f=->s{ #Input in s.
c=0 #Set current position of pointer to 0.
s.tr(". ","[\\"). #Change . and space to the characters after Z [\
bytes{|b| #For each byte b,
b-=65 #subtract 65 so A->0 B->1 etc.
print ["","^","^^","v"][c/7-b/7], #Print the necessary string to move vertically.
(d=(c-c=b)%7)>3? #Calculate the horizontal difference c-b (mod 7) and set c to b ready for next byte.
?>*(7-d):?<*d, #If d>3 print an appropriate number of >, else an appropriate number of <.
?. #Print . to finish the processing of this byte.
}
}
#call like this and print a newline after each testcase
f["FLP.TKC"];puts
f["MOYLEX"];puts
f["FEERSUM"];puts
f["MEGO"];puts
f["A CAT"];puts
f["BOB"];puts