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

26 lines
831 B
Text

scope # find words whose characters are in alphabetical order
local proc isSorted( word :: string ) :: boolean
local result := true;
for c to size word - 1 while result do
result := word[ c ] <= word[ c + 1 ]
od;
return result
end;
local sortedWords, maxLength := seq(), 0;
for word in io.lines( "unixdict.txt" ) do
if isSorted( word ) then
local constant thisLength := size word;
if thisLength >= maxLength then
if thisLength > maxLength then
clear sortedWords;
sortedWords, maxLength := seq(), thisLength
fi;
sortedWords[ size sortedWords + 1 ] := word
fi
fi
od;
for _, w in ipairs( sortedWords ) do print( w ) od
end