RosettaCodeData/Task/Ordered-words/Pluto/ordered-words.pluto
2026-04-30 12:34:36 -04:00

24 lines
744 B
Text

do -- find words whose characters are in alphabetical order
local function isSorted( word : string ) : boolean
for c = 1, # word - 1 do
if word[ c ] > word[ c + 1 ] then return false end
end
return true
end
local sortedWords, maxLength = {}, 0
for word in io.lines( "unixdict.txt" ) do
if isSorted( word ) then
local thisLength <const> = # word
if thisLength >= maxLength then
if thisLength > maxLength then
sortedWords, maxLength = {}, thisLength
end
sortedWords[ # sortedWords + 1 ] = word
end
end
end
for _, w in ipairs( sortedWords ) do print( w ) end
end