Longest Word With Just Half a Keyboard?
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:
[perl] #!/usr/bin/perl use strict;
my $longestLeft, my $longestRight;
while(<>){ my $validLeft = $_ unless m/[yuiophjklnm]/i; my $validRight = $_ unless m/[qwertasdfgzxcvb]/i; $longestLeft = $validLeft if length($validLeft) > length($longestLeft); $longestRight = $validRight if length($validRight) > length($longestRight); }
print “Longest left-only: $longestLeft\nLongest right-only: $longestRight\n”; [/perl]
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:
[perl] #!/usr/bin/perl use strict;
# declare the needed variables my $longestLeft, my $longestRight, my $minLength=10; my @longLeftWords, my @longRightWords;
# loop through the dictionary (file name to be passed as only argument) while(<>){ chomp; unless(m/[yuiophjklnm]/i){ # valid left-only word push(@longLeftWords, $_) if length($_) >= $minLength; $longestLeft = $_ if length($_) > length($longestLeft); } unless(m/[qwertasdfgzxcvb]/i){ # valid right-only word push(@longRightWords, $_) if length($_) >= $minLength; $longestRight = $_ if length($_) > length($longestRight); } }
# print the results print “\nLong words (at least $minLength letters) with the left-side of the KB only:\n”; foreach my $word (@longLeftWords){ print “\t$word\n”; } print “\t\t(total: “.scalar(@longLeftWords).”)\n”; print “\nLong words (at least $minLength letters) with the rightside of the KB only:\n”; foreach my $word (@longRightWords){ print “\t$word\n”; } print “\t\t(total: “.scalar(@longRightWords).”)\n”; print “\nLongest left-only word: $longestLeft (“.length($longestLeft).” letters)\n”; print “Longest right-only word: $longestRight (“.length($longestLeft).” letters)\n\n”; [/perl]
This gives the following results: [code] bartmbp:Temp bart$ ./dict.pl /usr/share/dict/words
Long words (at least 10 letters) with the left-side of the KB only: abracadabra abstracted abstracter Actaeaceae afterbreast aftercareer aftercataract aftereffect aftergrass aftergrave afterstate aftertaste afterwards Aggregatae asarabacca assertress asseverate Asteraceae badgerweed beaverette bedaggered begartered beggarweed besweatered betattered bettergates breastweed cataracted decerebrate defervesce desecrater desertress desertward detractress devertebrated ebracteate effervesce estafetted everbearer Evertebrata evertebrate exacerbate exaggerate exaggerated extrastate extravagate extravasate freetrader Gastraeadae gazetteerage grasswards gravestead gravewards reaggravate reaggregate reasseverate redecrease redefecate refederate regratress Resedaceae retraverse revegetate reverberate reverbrate settergrass stagecraft staggerweed starveacre statecraft stavesacre stewardess streetward sweetbread sweetwater tartarated terracette terracewards tessaradecad tesseradecade tesserated tradecraft Trastevere versecraft Vertebrata vertebrate vertebrated waterstead waterwards westerwards (total: 90)
Long words (at least 10 letters) with the rightside of the KB only: hypolimnion hypophyllium hypophyllum miminypiminy phyllophyllin Plynlymmon polyphonium polyphylly (total: 8)
Longest left-only word: aftercataract (13 letters) Longest right-only word: phyllophyllin (13 letters)
bartmbp:Temp bart$ [/code]
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.