Anonymous user
Subset sum problem: Difference between revisions
m
→{{header|REXX}}: re-did the REXX program, combined some statements, removed some blank lines. -- ~~~~
m (→{{header|Haskell}}: hrm) |
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
end
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
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
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
|