! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license.
-USING: fry grouping http.client io io.encodings.utf8 io.files
-io.files.temp kernel math math.order memoize sequences
-unicode.case urls ;
+USING: grouping http.client io io.encodings.utf8 io.files
+io.files.temp kernel math sequences sequences.extras
+unicode urls ;
IN: rosetta-code.ordered-words
! http://rosettacode.org/wiki/Ordered_words
! this page.
MEMO: word-list ( -- seq )
- "unixdict.txt" temp-file dup exists? [
- URL" http://puzzlers.org/pub/wordlists/unixdict.txt"
- over download-to
- ] unless utf8 file-lines ;
+ URL" http://puzzlers.org/pub/wordlists/unixdict.txt"
+ "unixdict.txt" temp-file
+ [ ?download-to ] [ utf8 file-lines ] bi ;
: ordered-word? ( word -- ? )
- >lower 2 <clumps> [ first2 <= ] all? ;
-
-: filter-longest-words ( seq -- seq' )
- dup [ length ] [ max ] map-reduce
- '[ length _ = ] filter ;
+ >lower [ <= ] monotonic? ;
: ordered-words-main ( -- )
word-list [ ordered-word? ] filter
- filter-longest-words [ print ] each ;
+ all-longest [ print ] each ;
MAIN: ordered-words-main