]> gitweb.factorcode.org Git - factor.git/commitdiff
math-binpack: Some cleanups recommended on IRC.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 Oct 2008 06:44:45 +0000 (23:44 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 Oct 2008 06:44:45 +0000 (23:44 -0700)
extra/math/binpack/binpack.factor

index f6473f2e25a7d62b9f230b9f76540a97207ef5ad..e3a009feb5c6dfebefb96d972d156051c68542f2 100644 (file)
@@ -6,16 +6,17 @@ USING: sequences kernel arrays vectors accessors assocs sorting math math.functi
 IN: math.binpack 
 
 : (binpack) ( bins item -- )
-    swap dup [ [ second ] map sum ] map swap zip sort-keys values first push ;
+    [ [ values sum ] map ] keep
+    zip sort-keys values first push ;
 
 : binpack ( assoc n -- bins )
-    [ sort-values reverse [ length ] keep swap ] dip 
-    [ / ceiling ] keep swap <array> [ <vector> ] map 
-    swap [ dupd (binpack) ] each ;
+    [ sort-values <reversed> dup length ] dip
+    tuck / ceiling <array> [ <vector> ] map
+    tuck [ (binpack) ] curry each ;
 
 : binpack* ( items n -- bins )
     [ dup zip ] dip binpack [ keys ] map ;
 
 : binpack! ( items quot n -- bins ) 
-    [ dup ] 2dip [ map zip ] dip binpack [ keys ] map ;
+    [ dupd map zip ] dip binpack [ keys ] map ;