Anonymous user
Knapsack problem/Continuous: Difference between revisions
m
→{{header|REXX}}: simplified a DO loop assignments, changed some indentations.
m (→{{header|REXX}}: simplified a DO loop assignments, changed some indentations.) |
|||
Line 1,645:
=={{header|REXX}}==
Any resemblence to the Fortran code is 120% coincidental.
<lang rexx>/*REXX program
@.= /*═══════ name weight value ══════*/
@.
@.
@.
@.
@.
@.
@.
@.
totW=0; totV=0
items=j-1 /*
nL=nL+nL%4 /*nL: max length name + ≈ 25%.
wL=max(wL,length(format(totw,,2))) /*wL: max formatted weight width*/
vL=max(vL,length(format(totv,,2))) /*vL: max formatted value width*/
totW=0; totV=0
call show '
do j=2 to items /*sort by desending value/unit wt*/
k=j-1; _n=n.j; _w=w.j; _v=v.j
do k=k by -1 to 1 while v.k/w.k < _v/_w
kp1=k+1; n.kp1=n.k;
end /*k*/
kp1=k+1; n.kp1=_n; w.kp1=_w; v.kp1=_v
end /*j*/
call hdr "burgler's knapsack contents"
maxW=15 /*burgler's knapsack max weight. */
Line 1,700 ⟶ 1,698:
call sy left('total value',nL,'─'), , format(totV,,2)
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────one─liner
hdr: indent=left('',9); call verse arg(1); call title; call sep; return
sep: call sy copies('═',nL), copies("═",wL), copies('═',vL); return
Line 1,710 ⟶ 1,708:
'''output'''
<pre style="height:50ex">
────────────────unsorted item list────────────────
item weight value
Line 1,723 ⟶ 1,721:
salami 3.00 95.00
sausage 5.90 98.00
▲ flitch 4.00 30.00
|