Anonymous user
Power set: Difference between revisions
m
→{{header|REXX}}: used a template for the output section, added/changed whitespace and comments, aligned some statements.
No edit summary |
m (→{{header|REXX}}: used a template for the output section, added/changed whitespace and comments, aligned some statements.) |
||
Line 3,245:
parse arg S /*allow the user specify optional set. */
if S='' then S= 'one two three four' /*Not specified? Then use the default.*/
@= '{}'
N= words(S); do chunk=1 for N
@=@ combN(N, chunk)
end /*chunk*/
w= length(2**N)
do k=1 for words(@)
say right(k, w) word(@, k)
end /*k*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
combN: procedure expose S; parse arg x,y;
$=
do j=1; L=
▲ $=$ '{'strip(L, "L", ',')"}"
if !.y==base then if .combU(y - 1) then leave
end /*j*/
return strip($) /*return with a partial powerset chunk.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
.combU: procedure expose !. y bbase; parse arg d; if d==0 then return 1
p= !.d
▲ do u=d to y; !.u=p+1; if !.u==bbase+u then return .combU(u-1)
if !.u==bbase+u then return .combU(u-1)
p= !.u
end /*u*/
return 0</lang>
<pre>
1 {}
|