#!/usr/bin/ruby
File.open('/usr/share/dict/words') { |f|
f.each do |word|
word.chomp!
word.downcase!
ordered = true
last = ''
word.split(//).each do |letter|
last = letter unless last.length
if letter > last
ordered = false
end
last = letter
end
puts word if ordered and word.length > 6
end
}
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:
Post a Comment