Anonymous user
Subset sum problem: Difference between revisions
m
→{{header|REXX}}: changed a REXX variable's name to make the code easier to read. -- ~~~~
(→{{header|REXX}}: added the results. -- ~~~~) |
m (→{{header|REXX}}: changed a REXX variable's name to make the code easier to read. -- ~~~~) |
||
Line 611:
<br>out of the 31 names, take a "chunk" at a time).
<br>Showing of the timing (elapsed time) was also added, as well as "que pasa" informational messages.
<br>The sum can be anything, not just zero as specifiable on the command line.
<lang rexx>/*REXX pgm finds some non-null subsets of a weighted list whose sum = 0.*/
arg target stopAt chunkette . /*get args from the command line*/
Line 635 ⟶ 636:
call esort N /*sort the names with weights.*/
call tellZ 'sorted' /*show the sorted list. */
chunkStart=1 /*default place to start. */
chunkEnd =N /* " " " end. */
Line 650 ⟶ 651:
end /*chunk*/
if
call tello 'Found'
exit /*stick a fork in it, we done.*/
/*──────────────────────────────────combN subroutine────────────────────*/
combN: procedure expose @. #.
base=x+1; bbase=base-y; ym=y-1 /*!.n are the combination digits*/
Line 702 ⟶ 703:
s: if arg(1)==1 then return arg(3); return word(arg(2) 's',1)
/*──────────────────────────────────telly subroutine────────────────────*/
telly:
do gi=1 for y; ggg=!.gi /*build dup array (to be sorted).*/
Line 715 ⟶ 716:
call tello '['y" name"s(y)']' space(nameL)
if
stopAt\==0 then do
call tello 'Stopped after finding'
exit /*a short-timer, we have to quit.*/
end
|