]> gitweb.factorcode.org Git - factor.git/blob - extra/rosetta-code/ordered-words/ordered-words.factor
factor: trim using lists
[factor.git] / extra / rosetta-code / ordered-words / ordered-words.factor
1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: grouping http.client io io.encodings.utf8 io.files
4 io.files.temp kernel math sequences sequences.extras
5 unicode urls ;
6 IN: rosetta-code.ordered-words
7
8 ! http://rosettacode.org/wiki/Ordered_words
9
10 ! Define an ordered word as a word in which the letters of the
11 ! word appear in alphabetic order. Examples include 'abbey' and
12 ! 'dirt'.
13
14 ! The task is to find and display all the ordered words in this
15 ! dictionary that have the longest word length. (Examples that
16 ! access the dictionary file locally assume that you have
17 ! downloaded this file yourself.) The display needs to be shown on
18 ! this page.
19
20 MEMO: word-list ( -- seq )
21     URL" http://puzzlers.org/pub/wordlists/unixdict.txt"
22     "unixdict.txt" temp-file
23     [ ?download-to ] [ utf8 file-lines ] bi ;
24
25 : ordered-word? ( word -- ? )
26     >lower [ <= ] monotonic? ;
27
28 : ordered-words-main ( -- )
29     word-list [ ordered-word? ] filter
30     all-longest [ print ] each ;
31
32 MAIN: ordered-words-main