Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,70 @@
|
|||
(knapsack=
|
||||
( things
|
||||
= (panacea.3000.3/10.25/1000)
|
||||
(ichor.1800.2/10.15/1000)
|
||||
(gold.2500.2.2/1000)
|
||||
)
|
||||
& 0:?maxvalue
|
||||
& :?sack
|
||||
& ( add
|
||||
= cumwght
|
||||
cumvol
|
||||
cumvalue
|
||||
cumsack
|
||||
name
|
||||
wght
|
||||
val
|
||||
vol
|
||||
tings
|
||||
n
|
||||
ncumwght
|
||||
ncumvalue
|
||||
ncumvol
|
||||
. !arg
|
||||
: ( ?cumwght
|
||||
. ?cumvol
|
||||
. ?cumvalue
|
||||
. ?cumsack
|
||||
. (?name.?val.?wght.?vol) ?tings
|
||||
)
|
||||
& -1:?n
|
||||
& whl
|
||||
' ( 1+!n:?n
|
||||
& !cumwght+!n*!wght:~>25:?ncumwght
|
||||
& !cumvol+!n*!vol:~>250/1000:?ncumvol
|
||||
& !cumvalue+!n*!val:?ncumvalue
|
||||
& ( !tings:
|
||||
& ( !ncumvalue:>!maxvalue:?maxvalue
|
||||
& !cumsack
|
||||
( !n:0&
|
||||
| ( !cumsack:&Take
|
||||
| Finally
|
||||
)
|
||||
" take "
|
||||
!n
|
||||
" items of "
|
||||
!name
|
||||
".\n"
|
||||
)
|
||||
: ?sack
|
||||
|
|
||||
)
|
||||
| add
|
||||
$ ( !ncumwght
|
||||
. !ncumvol
|
||||
. !ncumvalue
|
||||
. !cumsack
|
||||
( !n:0&
|
||||
| "Take " !n " items of " !name ".\n"
|
||||
)
|
||||
. !tings
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
& add$(0.0.0..!things)
|
||||
& out$(str$(!sack "The value in the knapsack is " !maxvalue "."))
|
||||
&
|
||||
);
|
||||
|
||||
!knapsack;
|
||||
Loading…
Add table
Add a link
Reference in a new issue