Paste: faster euler23

Author: jon
Mode: patch
Date: Wed, 30 Sep 2009 09:53:46
Plain Text |
diff --git a/extra/project-euler/023/023.factor b/extra/project-euler/023/023.factor
index 7c28ebf..a1894cf 100644
--- a/extra/project-euler/023/023.factor
+++ b/extra/project-euler/023/023.factor
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.ranges project-euler.common sequences sets sorting ;
+USING: kernel math math.ranges project-euler.common sequences sets sorting locals assocs ;
 IN: project-euler.023
 
 ! http://projecteuler.net/index.php?section=problems&id=23
@@ -42,10 +42,8 @@ IN: project-euler.023
     [1,b] [ abundant? ] filter ;
 
 : possible-sums ( seq -- seq )
-    dup { } -rot [
-        dupd [ + ] curry map
-        rot append prune swap rest
-    ] each drop natural-sort ;
+    [let | table  [ H{ } ] |
+    dup [ [ + t swap table set-at ] with each ] curry each table keys ] ;
 
 PRIVATE>
 
@@ -53,6 +51,8 @@ PRIVATE>
     source-023
     20161 abundants-upto possible-sums diff sum ;
 
+
+
 ! TODO: solution is still too slow, although it takes under 1 minute
 
 ! [ euler023 ] time

Annotation: with fry

Author: Sam
Mode: factor
Date: Wed, 30 Sep 2009 10:19:44
Plain Text |
diff --git a/extra/project-euler/023/023.factor b/extra/project-euler/023/023.factor
index 7c28ebf..16d1f63 100644
--- a/extra/project-euler/023/023.factor
+++ b/extra/project-euler/023/023.factor
@@ -1,6 +1,7 @@
 ! Copyright (c) 2008 Aaron Schaefer.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.ranges project-euler.common sequences sets sorting ;
+USING: assocs fry kernel math math.ranges project-euler.common sequences
+sets sorting ;
 IN: project-euler.023
 
 ! http://projecteuler.net/index.php?section=problems&id=23
@@ -42,10 +43,8 @@ IN: project-euler.023
     [1,b] [ abundant? ] filter ;
 
 : possible-sums ( seq -- seq )
-    dup { } -rot [
-        dupd [ + ] curry map
-        rot append prune swap rest
-    ] each drop natural-sort ;
+    dup H{ } clone
+    [ '[ [ + _ conjoin ] with each ] curry each ] keep keys ;

Annotation: another

Author: jon
Mode: factor
Date: Wed, 30 Sep 2009 10:24:05
Plain Text |
: possible-sums ( seq -- seq )
    H{ } clone
    [ dupd '[ _ [ + _ conjoin ] with each ] each ]
    [ keys ] bi ;

New Annotation

Summary:
Author:
Mode:
Body: