Power set: Difference between revisions

Content deleted Content added
→‎{{header|REXX}}: added the REXX language. -- ~~~~
m →‎{{header|REXX}}: changed the "set" variable name to '''S'''. -- ~~~~
Line 1,704: Line 1,704:
=={{header|REXX}}==
=={{header|REXX}}==
<lang rexx>/*REXX program to display a power set, items may be anything (no blanks)*/
<lang rexx>/*REXX program to display a power set, items may be anything (no blanks)*/
parse arg set /*let user specify the items. */
parse arg S /*let user specify the set. */
if set=='' then set='one two three four' /*None specified? Use default*/
if S='' then S='one two three four' /*None specified? Use default*/
N=words(set) /*number of items in the list.*/
N=words(S) /*number of items in the list.*/
ps='{}' /*start with a null power set.*/
ps='{}' /*start with a null power set.*/
do chunk=1 for N /*traipse through the items. */
do chunk=1 for N /*traipse through the items. */
Line 1,717: Line 1,717:
exit /*stick a fork in it, we done.*/
exit /*stick a fork in it, we done.*/
/*─────────────────────────────────────$COMBN subroutine────────────────*/
/*─────────────────────────────────────$COMBN subroutine────────────────*/
combN: procedure expose $ set; parse arg x,y; $=
combN: procedure expose $ S; parse arg x,y; $=
!.=0; base=x+1; bbase=base-y; ym=y-1; do p=1 for y; !.p=p; end
!.=0; base=x+1; bbase=base-y; ym=y-1; do p=1 for y; !.p=p; end
do j=1; L=
do j=1; L=
do d=1 for y; _=!.d; L=L','word(set,_); end
do d=1 for y; _=!.d; L=L','word(S,_); end
$=$ '{'strip(L,'L',",")'}'
$=$ '{'strip(L,'L',",")'}'
!.y=!.y+1; if !.y==base then if .combU(ym) then leave
!.y=!.y+1; if !.y==base then if .combU(ym) then leave