]> gitweb.factorcode.org Git - factor.git/blob - extra/rosetta-code/ordered-words/ordered-words.factor
0ce7c4319e0e2872d27c723cb3f6e34f11e9d229
[factor.git] / extra / rosetta-code / ordered-words / ordered-words.factor
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
6
7 ! https://rosettacode.org/wiki/Ordered_words
8
9 ! Define an ordered word as a word in which the letters of the
10 ! word appear in alphabetic order. Examples include 'abbey' and
11 ! 'dirt'.
12
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
17 ! this page.
18
19 MEMO: word-list ( -- seq )
20     URL" https://raw.githubusercontent.com/quinnj/Rosetta-Julia/master/unixdict.txt"
21     "unixdict.txt" temp-file
22     download-to utf8 file-lines ;
23
24 : ordered-word? ( word -- ? )
25     >lower [ <= ] monotonic? ;
26
27 : ordered-words-main ( -- )
28     word-list [ ordered-word? ] filter
29     all-longest [ print ] each ;
30
31 MAIN: ordered-words-main