@thattommyhall posted a fun question on Twitter:
If you type your name on a keyboard marked as qwerty but set to Dvorak and keep reinputting what comes out, will it ever say your name?
— !!!!!11111oneoneone (@thattommyhall) July 31, 2014
The best answer was “yes because group theory” and @AnnaPawlicka demonstrated it was true for her name:
@thattommyhall Yes. I can confirm that. :) pic.twitter.com/Vubkf1ltoK
— Anna Pawlicka (@AnnaPawlicka) July 31, 2014
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 |
|
1 2 3 4 |
|
This allows us to visualize the mapping of keys from one layout to another:
1
|
|
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 |
|
1 2 3 4 5 6 7 |
|
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 |
|
1
|
|
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 |
|
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 |
|
1
|
|