Handbook
Glossary
extract-packed-items ( table -- items )
Vocabulary
rosetta-code
.
knapsack
Inputs
table
an
object
Outputs
items
an
object
Definition
USING:
accessors
kernel
make
math
sequences
;
IN:
rosetta-code.knapsack
::
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
;