Anonymous user
Power set: Difference between revisions
m
→{{header|REXX}}: added/changed whitespace and comments.
m (→Non-recursive version: Fix syntax) |
m (→{{header|REXX}}: added/changed whitespace and comments.) |
||
Line 3,280:
end /*chunk*/
w= length(2**N) /*the number of items in the power set.*/
do k=1 for words(@) /* [↓] show combinations,
say right(k, w) word(@, k) /*display a single combination to term.*/
end /*k*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
combN: procedure expose S; parse arg x,y; base= x + 1;
!.= 0
do p=1 for y; !.p= p
end /*p*/
$=
do j=1; L=; do d=1 for y; L= L','word(S, !.d)
$=$ '{'strip(L, "L", ',')"}"; !.y= !.y + 1
if !.y==base then if .combU(y - 1) then leave
end /*j*/
return strip($) /*return with a partial
/*──────────────────────────────────────────────────────────────────────────────────────*/
.combU: procedure expose !. y bbase;
p= !.d
end
return 0</lang>
{{out|output|text= when using the default input:}}
|