From 1c76a6865a310a10035fbf8806ff4f5b27590f4d Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 1 Oct 2008 23:44:45 -0700 Subject: [PATCH] math-binpack: Some cleanups recommended on IRC. --- extra/math/binpack/binpack.factor | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/extra/math/binpack/binpack.factor b/extra/math/binpack/binpack.factor index f6473f2e25..e3a009feb5 100644 --- a/extra/math/binpack/binpack.factor +++ b/extra/math/binpack/binpack.factor @@ -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 [ ] map - swap [ dupd (binpack) ] each ; + [ sort-values dup length ] dip + tuck / ceiling [ ] 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 ;