Tuesday, February 06, 2007

Longest alphabetical word in English

Inspired by a list of 50 bogus "facts everbody should know" I found on what turned out to be a spammer's site, I decided to find the longest word in the English language where all the letters are in alphabetical order (the site claimed it was 'almost'). I whipped up a quick Ruby program:


File.open('/usr/share/dict/words') { |f|
f.each do |word|
ordered = true

last = ''
word.split(//).each do |letter|
last = letter unless last.length
if letter > last
ordered = false
last = letter
puts word if ordered and word.length > 6

It's been a while since I wrote Ruby, so originally I had "ordered = 1" and set it to 0, instead of false, in the if statement in the middle. This is wrong, because Ruby distinguishes between the number 0 and false, unlike C and many other derived languages (Perl distinguishes between them, but allows 0 to mean false in a conditional).

Anyway, as it turns out, the answer is 'billowy', at least according to /usr/share/dict/words. In case you were curious.

No comments: