Power set: Difference between revisions

Content added Content deleted
(Add APL)
m (→‎{{header|REXX}}: added/changed whitespace and comments, split a compound statement.)
Line 3,362: Line 3,362:
say right(k, w) word(@, k) /*display a single combination to term.*/
say right(k, w) word(@, k) /*display a single combination to term.*/
end /*k*/
end /*k*/
exit /*stick a fork in it, we're all done. */
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
combN: procedure expose S; parse arg x,y; base= x + 1; bbase= base - y
combN: procedure expose S; parse arg x,y; base= x + 1; bbase= base - y
!.= 0
!.= 0
do p=1 for y; !.p= p
do p=1 for y; !.p= p
end /*p*/
end /*p*/
$= /* [↓] build powerset*/
$=
do j=1; L=; do d=1 for y; L= L','word(S, !.d)
do j=1; L=
end /*d*/
do d=1 for y; L= L','word(S, !.d)
$=$ '{'strip(L, "L", ',')"}"; !.y= !.y + 1
end /*d*/
if !.y==base then if .combU(y - 1) then leave
$= $ '{'strip(L, "L", ',')"}"; !.y= !.y + 1
end /*j*/
if !.y==base then if .combU(y - 1) then leave
end /*j*/
return strip($) /*return with a partial power set chunk*/
return strip($) /*return with a partial power set chunk*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
Line 3,379: Line 3,380:
p= !.d
p= !.d
do u=d to y; !.u= p + 1; if !.u==bbase+u then return .combU(u-1)
do u=d to y; !.u= p + 1; if !.u==bbase+u then return .combU(u-1)
p= !.u
p= !.u /* ↑ */
end /*u*/
end /*u*/ /*recurse──►───┘ */
return 0</lang>
return 0</lang>
{{out|output|text=&nbsp; when using the default input:}}
{{out|output|text=&nbsp; when using the default input:}}