Handbook
Glossary
iterate ( item-no table -- )
Vocabulary
rosetta-code
.
knapsack
Inputs
item-no
an
object
table
an
object
Outputs
None
Definition
USING:
accessors
kernel
math
math.order
ranges
sequences
;
IN:
rosetta-code.knapsack
::
iterate
( item-no table -- )
item-no table
nth
:>
prev item-no 1
+
table
nth
:>
curr item-no
items
nth
:>
item
limit
[1..b]
[|
weight |
weight prev
nth
weight item
weight>>
-
dup
0
>=
[
prev
nth
item
value>>
+
max
]
[
drop
]
if
weight curr
set-nth
]
each
;