Jump to content

Subset sum problem: Difference between revisions

m
→‎{{header|REXX}}: re-did the REXX program, combined some statements, removed some blank lines. -- ~~~~
m (→‎{{header|REXX}}: re-did the REXX program, combined some statements, removed some blank lines. -- ~~~~)
Line 811:
call tello 'Found' ?? "subset"s(??) 'whose summed weight's(??) "=" target
exit /*stick a fork in it, we done.*/
 
/*──────────────────────────────────COMBN subroutine────────────────────*/
combN: procedure expose @. #. ?? stopAt target; parse arg x,y; !.=0
base=x+1; bbase=base-y; ym=y-1 /*!.n are the combination digits*/
 
do n=1 for y; !.n=n; end /*build 1st combination*/
 
Line 836 ⟶ 834:
end /*u*/
return 0 /*go back & sum this combination.*/
 
/*──────────────────────────────────ESORT subroutine────────────────────*/
esort: procedure expose #. @.; parse arg N; h=N
do while h>1; h=h%2
do i=1 for N-h; j=i; k=h+i
do while #.k<#.j; parse value @.j @.k #.j #.k with @.k @.j #.k #.j
parseif valueh>=j then leave; @.j @.k #.j=j-h; #.k with @.k @.j #.=k #.j-h
if h>=j then leave;end /*while #.k<#.j=j-h; k=k-h*/
end end /*while #.k<#.ji*/
end /*iwhile h>1*/
end /*while h>1*/
return
 
/*──────────────────────────────────NSORT subroutine────────────────────*/
nSort: procedure expose names.; parse arg many; h=many
do while h>1; h=h%2
do i=1 for many-h; j=i; k=h+i
do while names.k<names.j; parse value names.j names.k with names.k names.j
parseif valueh>=j then leave; names.j names.k withj=j-h; names.k names.j k=k-h
if h>=j then leave; j=j-h; k=k-h
end /*while names.k<names.j*/
end /*i*/
end /*while h>1*/
return
 
/*──────────────────────────────────S subroutine────────────────────────*/
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1) /*plural*/
 
/*──────────────────────────────────TELLO subroutine────────────────────*/
tello: say arg(1); call lineout 'SUBSET.'y,arg(1) /*write to file*/; return
 
/*──────────────────────────────────TELLY subroutine────────────────────*/
telly: ??=??+1; nameL= /*start with a "null" name list. */
Line 886 ⟶ 877:
end
return /*go back and keep on truckin'. */
 
/*──────────────────────────────────TELLZ subroutine────────────────────*/
tellz: do Jj=1 for N /*show list of names and weights.*/
call tello right('['j']',30) right(@.j,11) right(#.j,5)
end /*j*/
call tello; call tello 'There are' N "entries in the (above)" arg(1) 'table.'
call tello
Cookies help us deliver our services. By using our services, you agree to our use of cookies.