1 ! Copyright (c) 2012 Anonymous
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: grouping http.download io io.encodings.utf8 io.files
4 io.files.temp math sequences sequences.extras unicode urls ;
5 IN: rosetta-code.ordered-words
7 ! https://rosettacode.org/wiki/Ordered_words
9 ! Define an ordered word as a word in which the letters of the
10 ! word appear in alphabetic order. Examples include 'abbey' and
13 ! The task is to find and display all the ordered words in this
14 ! dictionary that have the longest word length. (Examples that
15 ! access the dictionary file locally assume that you have
16 ! downloaded this file yourself.) The display needs to be shown on
19 MEMO: word-list ( -- seq )
20 URL" https://raw.githubusercontent.com/quinnj/Rosetta-Julia/master/unixdict.txt"
21 "unixdict.txt" temp-file
22 download-once-to utf8 file-lines ;
24 : ordered-word? ( word -- ? )
25 >lower [ <= ] monotonic? ;
27 : ordered-words-main ( -- )
28 word-list [ ordered-word? ] filter
29 all-longest [ print ] each ;
31 MAIN: ordered-words-main