As some of you may know, I’ve been ill for the past few weeks now, and hence not working or podcasting. I spend a lot of my time doing nothing because I have no energy and often a headache, but when my head is clear I have a lot of thinking time since doing physical things is not possible. I even need to be careful not to type too much or my arms get very sore!

Anyhow – yesterday Bren Finan was chatting with me when he noticed that ‘yesterday’ uses only keys from one half of the keyboard. Which got him, and hence me, wondering if there was a longer word that can be written with just half a keyboard. (The quick-witted among you will probably spot that ‘Yesterday’ doesn’t actually count because the ‘y’ is on the wrong side of the divide on ergonomic keyboards.)

As I say, the conversation got me thinking, and I mentioned it to Connor P when I was chatting to him later, and during that conversation the idea came to write a program to get the answer! The problem then was that I’d need a dictionary file. Connor soon found the answer on Google, the Mac has a built-in word list in /usr/share/dict/words! So, all it took was a few lines of Perl:

  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. my $longestLeft, my $longestRight;
  5.  
  6. while(<>){
  7.     my $validLeft = $_ unless m/[yuiophjklnm]/i;
  8.     my $validRight = $_ unless m/[qwertasdfgzxcvb]/i;
  9.     $longestLeft = $validLeft if length($validLeft) > length($longestLeft);
  10.     $longestRight = $validRight if length($validRight) > length($longestRight);
  11. }
  12.  
  13. print "Longest left-only: $longestLeft\nLongest right-only: $longestRight\n";

The answer, the longest left-only word is ‘aftercataract’, and the longest right-only word is ‘phyllophyllin’!

Of coruse, once I started thinking about this I also wanted a list of long words, so I did a few teaks to the code, and produced this delux version:

  1. #!/usr/bin/perl
  2. use strict;
  3.  
  4. # declare the needed variables
  5. my $longestLeft, my $longestRight, my $minLength=10;
  6. my @longLeftWords, my @longRightWords;
  7.  
  8. # loop through the dictionary (file name to be passed as only argument)
  9. while(<>){
  10.     chomp;
  11.     unless(m/[yuiophjklnm]/i){
  12.         # valid left-only word
  13.         push(@longLeftWords, $_) if length($_) >= $minLength;
  14.         $longestLeft = $_ if length($_) > length($longestLeft);
  15.     }
  16.     unless(m/[qwertasdfgzxcvb]/i){
  17.         # valid right-only word
  18.         push(@longRightWords, $_) if length($_) >= $minLength;
  19.         $longestRight = $_ if length($_) > length($longestRight);
  20.     }
  21. }
  22.  
  23. # print the results
  24. print "\nLong words (at least $minLength letters) with the left-side of the KB only:\n";
  25. foreach my $word (@longLeftWords){
  26.     print "\t$word\n";
  27. }
  28. print "\t\t(total: ".scalar(@longLeftWords).")\n";
  29. print "\nLong words (at least $minLength letters) with the rightside of the KB only:\n";
  30. foreach my $word (@longRightWords){
  31.     print "\t$word\n";
  32. }
  33. print "\t\t(total: ".scalar(@longRightWords).")\n";
  34. print "\nLongest left-only word: $longestLeft (".length($longestLeft)." letters)\n";
  35. print "Longest right-only word: $longestRight (".length($longestLeft)." letters)\n\n";

This gives the following results:

  1. bartmbp:Temp bart$ ./dict.pl /usr/share/dict/words
  2.  
  3. Long words (at least 10 letters) with the left-side of the KB only:
  4.     abracadabra
  5.     abstracted
  6.     abstracter
  7.     Actaeaceae
  8.     afterbreast
  9.     aftercareer
  10.     aftercataract
  11.     aftereffect
  12.     aftergrass
  13.     aftergrave
  14.     afterstate
  15.     aftertaste
  16.     afterwards
  17.     Aggregatae
  18.     asarabacca
  19.     assertress
  20.     asseverate
  21.     Asteraceae
  22.     badgerweed
  23.     beaverette
  24.     bedaggered
  25.     begartered
  26.     beggarweed
  27.     besweatered
  28.     betattered
  29.     bettergates
  30.     breastweed
  31.     cataracted
  32.     decerebrate
  33.     defervesce
  34.     desecrater
  35.     desertress
  36.     desertward
  37.     detractress
  38.     devertebrated
  39.     ebracteate
  40.     effervesce
  41.     estafetted
  42.     everbearer
  43.     Evertebrata
  44.     evertebrate
  45.     exacerbate
  46.     exaggerate
  47.     exaggerated
  48.     extrastate
  49.     extravagate
  50.     extravasate
  51.     freetrader
  52.     Gastraeadae
  53.     gazetteerage
  54.     grasswards
  55.     gravestead
  56.     gravewards
  57.     reaggravate
  58.     reaggregate
  59.     reasseverate
  60.     redecrease
  61.     redefecate
  62.     refederate
  63.     regratress
  64.     Resedaceae
  65.     retraverse
  66.     revegetate
  67.     reverberate
  68.     reverbrate
  69.     settergrass
  70.     stagecraft
  71.     staggerweed
  72.     starveacre
  73.     statecraft
  74.     stavesacre
  75.     stewardess
  76.     streetward
  77.     sweetbread
  78.     sweetwater
  79.     tartarated
  80.     terracette
  81.     terracewards
  82.     tessaradecad
  83.     tesseradecade
  84.     tesserated
  85.     tradecraft
  86.     Trastevere
  87.     versecraft
  88.     Vertebrata
  89.     vertebrate
  90.     vertebrated
  91.     waterstead
  92.     waterwards
  93.     westerwards
  94.         (total: 90)
  95.  
  96. Long words (at least 10 letters) with the rightside of the KB only:
  97.     hypolimnion
  98.     hypophyllium
  99.     hypophyllum
  100.     miminypiminy
  101.     phyllophyllin
  102.     Plynlymmon
  103.     polyphonium
  104.     polyphylly
  105.         (total: 8)
  106.  
  107. Longest left-only word: aftercataract (13 letters)
  108. Longest right-only word: phyllophyllin (13 letters)
  109.  
  110. bartmbp:Temp bart$

This tells me two things, firstly, that Perl is really good at analysing text, because on my 5 year old Macbook Pro that took about a second to run, and second, that there are FAR more words for the left side than the right side.