RosettaCodeData/Task/Ordered-words/Phix/ordered-words.phix
2016-12-05 23:44:36 +01:00

34 lines
649 B
Text

type ordered(sequence s)
for i=1 to length(s)-1 do
-- assume all items in the sequence are atoms
if s[i]>s[i+1] then
return 0
end if
end for
return 1
end type
integer maxlen
sequence words
object word
constant fn = open("demo\\unixdict.txt","r")
maxlen = -1
while 1 do
word = gets(fn)
if atom(word) then
exit
end if
word = trim(word)
if length(word)>=maxlen and ordered(lower(word)) then
if length(word)>maxlen then
maxlen = length(word)
words = {}
end if
words = append(words,word)
end if
end while
close(fn)
?words