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

29 lines
963 B
Fennel

(do ;;; find words whose characters are in alphabetical order
(fn sorted? [word]
(local word-length (length word))
(var (result c) (values true 1))
(while (and result (< c word-length))
(local c1 (+ c 1))
(set result (<= (word:sub c c) (word:sub c1 c1)))
(set c c1)
)
result
)
(var (sorted-words max-length) (values {} 0))
(each [word (io.lines "unixdict.txt")]
(when (sorted? word)
(local this-length (length word))
(when (>= this-length max-length)
(when (> this-length max-length)
(set (sorted-words max-length)
(values {} this-length)
)
)
(table.insert sorted-words word)
)
)
)
(each [_ w (ipairs sorted-words)] (print w))
)