Typing Qwerty on a Dvorak Keyboard

@thattommyhall posted a fun question on Twitter:

The best answer was “yes because group theory” and @AnnaPawlicka demonstrated it was true for her name:

But is it really true? And if so, how many iterations will it take to get the target string? I turned to Mathematica…

1
2
3
4
5
6
7
8
9
10
qwerty =
  {"-", "=",
   "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", "\\",
   "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "'",
   "z", "x", "c", "v", "b", "n", "m", ",", ".", "/"};
dvorak =
  {"[", "]",
   "'", ",", ".", "p", "y", "f", "g", "c", "r", "l", "/", "=", "\\",
   "a", "o", "e", "u", "i", "d", "h", "t", "n", "s", "-",
   ";", "q", "j", "k", "x", "b", "m", "w", "v", "z"};
1
2
3
4
KeyGraph[from_, to_] :=
 Graph[
  MapThread[#1 -> #2 &, {from, to}],
  VertexLabels -> "Name", DirectedEdges -> True]

This allows us to visualize the mapping of keys from one layout to another:

1
KeyGraph[dvorak, qwerty]

Dvorak to Qwerty Graph

There is a single directed edge going from each character to the one that will be displayed when you type it. There are 3 keys that remain unchanged, 2 pairs of swapped keys, and 2 large cycles of keys.

We can get these groups programmatically using the ConnectedComponents function:

1
2
3
4
TableForm @
 Sort @
  ConnectedComponents @
   KeyGraph[dvorak, qwerty]
Output
1
2
3
4
5
6
7
\
a
m
] =
, w
. e y t f g u c i d h j k v
[ - ' q p r o l / s n ; z x b

It will take the length of the cycle the letter is in to get the letter we want. For a given word, we won’t get all the letters we want unless we’ve iterated some multiple of the length of the cycles each letter is in. Let’s apply the Least Common Multiple function to see the worst case where there is a letter from each cycle:

1
2
3
4
LCM @@
 Length /@
  ConnectedComponents @
   KeyGraph[dvorak, qwerty]
Output
1
210

Looks like Anna got lucky that her name only consists of letters in a cycle of length 1 and 15.

For fun, here’s the graph we get if we use Colemak instead of Dvorak:

1
2
3
4
5
6
7
colemak =
  {"-", "=",
   "q", "w", "f", "p", "g", "j", "l", "u", "y", ";", "[", "]", "\\",
   "a", "r", "s", "t", "d", "h", "n", "e", "i", "o", "'",
   "z", "x", "c", "v", "b", "k", "m", ",", ".", "/"};

KeyGraph[colemak, qwerty]

Colemak to Qwerty Graph

One cycle of length 14, one cycle of length 3, and the rest are just letters that map back to themselves.

1
2
3
4
LCM @@
 Length /@
  ConnectedComponents @
   KeyGraph[colemak, qwerty]
Output
1
42

Comments