Sort by Length for OCaml Golf Competition by eldesh(rakuda)

open String;;
let rec f s=try f(input_line stdin::s)with End_of_file->s in
let c x y=let l,r=length x,length y in
if l=r then compare x y else l-r
in List.map (fun x->print_string (x^"\n")) (List.sort c (f []));;

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page