! Copyright (c) 2012 Anonymous
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators kernel locals math math.order
+USING: accessors combinators kernel math math.order
math.vectors sequences sequences.product combinators.short-circuit ;
IN: rosetta-code.knapsack-unbounded
! He can only take whole units of any item, but there is much
! more of any item than he could ever carry
-! How many of each item does he take to maximise the value of
+! How many of each item does he take to maximize the value of
! items he is carrying away with him?
! Note:
-! There are four solutions that maximise the value taken. Only
+! There are four solutions that maximize the value taken. Only
! one need be given.
CONSTANT: values { 3000 1800 2500 }
: <bounty> ( items -- bounty )
[ bounty new ] dip {
[ >>amounts ]
- [ values v. >>value ]
- [ weights v. >>weight ]
- [ volumes v. >>volume ]
+ [ values vdot >>value ]
+ [ weights vdot >>weight ]
+ [ volumes vdot >>volume ]
} cleave ;
: valid-bounty? ( bounty -- ? )
] 2map ;
: best-bounty ( -- bounty )
- find-max-amounts [ 1 + iota ] map <product-sequence>
+ find-max-amounts [ 1 + <iota> ] map <product-sequence>
[ <bounty> ] [ max ] map-reduce ;
-