Ordered words: Difference between revisions

add Standard ML
(Added missing type; removed HTTP access as file cannot be loaded at the given address (so used a local copy); other minor changes.)
(add Standard ML)
Line 4,216:
knotty
</pre>
 
=={{header|Standard ML}}==
<lang sml>fun isOrdered s =
let
fun loop (i, c) =
let
val c' = String.sub (s, i)
in
c <= c' andalso loop (i + 1, c')
end
handle Subscript => true
in
loop (0, #"\^@")
end
 
fun longestOrdereds (s, prev as (len, lst)) =
let
val len' = size s
in
if len' >= len andalso isOrdered s then
if len' = len then (len, s :: lst) else (len', [s])
else
prev
end
 
val () = print ((String.concatWith " "
o #2
o foldr longestOrdereds (0, [])
o String.tokens Char.isSpace
o TextIO.inputAll) TextIO.stdIn ^ "\n")</lang>
{{out}}
<pre>abbott accent accept access accost almost bellow billow biopsy chilly choosy choppy effort floppy glossy knotty</pre>
 
=={{header|Swift}}==
559

edits