]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/rosetta-code/ordered-words/ordered-words.factor
factor: trim using lists
[factor.git] / extra / rosetta-code / ordered-words / ordered-words.factor
index 95b6d3f42cc1d9ab1cf8ea319ad57daca494c98b..4f8fa616f5ad231bf61590aee30894b409d7ce77 100644 (file)
@@ -1,8 +1,8 @@
 ! 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
@@ -18,20 +18,15 @@ IN: rosetta-code.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