extract-packed-items ( table -- items )


Vocabulary
rosetta-code.knapsack

Inputs
tablean object


Outputs
itemsan object


Definition


:: extract-packed-items ( table -- items )
[
limit :> weight! items length <iota> <reversed> [|
item-no |
item-no table nth :> prev item-no 1 + table nth
:> curr weight [ curr nth ] [ prev nth ] bi = [
item-no items nth
[ name>> , ] [ weight>> weight swap - weight! ]
bi
] unless
] each
] { } make ;