]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/benchmark/beust2/beust2.factor
factor: trim using lists
[factor.git] / extra / benchmark / beust2 / beust2.factor
old mode 100755 (executable)
new mode 100644 (file)
index f96dc77..18d78cf
@@ -1,41 +1,38 @@
 ! Copyright (C) 2008 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: math math.ranges math.parser sequences kernel io locals ;
+USING: kernel math sequences ;
 IN: benchmark.beust2
 
 ! http://crazybob.org/BeustSequence.java.html
 
 :: (count-numbers) ( remaining first value used max listener: ( -- ) -- ? )
-    10 first - [| i |
-        [let* | digit [ i first + ]
-                mask [ digit 2^ ]
-                value' [ i value + ] |
-            used mask bitand zero? [
-                value max > [ t ] [
-                    remaining 1 <= [
-                        listener call f
-                    ] [
-                        remaining 1-
-                        0
-                        value' 10 *
-                        used mask bitor
-                        max
-                        listener
-                        (count-numbers)
-                    ] if
+    10 first - <iota> [| i |
+        i first + :> digit
+        digit 2^ :> mask
+        i value + :> value'
+        used mask bitand zero? [
+            value max > [ t ] [
+                remaining 1 <= [
+                    listener call f
+                ] [
+                    remaining 1 -
+                    0
+                    value' 10 *
+                    used mask bitor
+                    max
+                    listener
+                    (count-numbers)
                 ] if
-            ] [ f ] if
-        ]
+            ] if
+        ] [ f ] if
     ] any? ; inline recursive
 
 :: count-numbers ( max listener -- )
-    10 [ 1+ 1 1 0 max listener (count-numbers) ] any? drop ;
-    inline
+    10 <iota> [ 1 + 1 1 0 max listener (count-numbers) ] any? drop ; inline
 
-:: beust ( -- )
-    [let | i! [ 0 ] |
-        10000000000 [ i 1+ i! ] count-numbers
-        i number>string " unique numbers." append print
-    ] ;
+:: beust2-benchmark ( -- )
+    0 :> i!
+    5000000000 [ i 1 + i! ] count-numbers
+    i 7063290 assert= ;
 
-MAIN: beust
+MAIN: beust2-benchmark