Power set: Difference between revisions
Content added Content deleted
mNo edit summary |
|||
Line 2,112: | Line 2,112: | ||
(λ(inner-set) (set-add inner-set element))))))) |
(λ(inner-set) (set-add inner-set element))))))) |
||
</lang> |
</lang> |
||
=={{header|Rascal}}== |
=={{header|Rascal}}== |
||
Line 2,241: | Line 2,243: | ||
[[], ["one"], ["two"], ["one", "two"], ["three"], ["one", "three"], ["two", "three"], ["one", "two", "three"]] |
[[], ["one"], ["two"], ["one", "two"], ["three"], ["one", "three"], ["two", "three"], ["one", "two", "three"]] |
||
#<Set: {#<Set: {}>, #<Set: {1}>, #<Set: {2}>, #<Set: {1, 2}>, #<Set: {3}>, #<Set: {1, 3}>, #<Set: {2, 3}>, #<Set: {1, 2, 3}>}> |
#<Set: {#<Set: {}>, #<Set: {1}>, #<Set: {2}>, #<Set: {1, 2}>, #<Set: {3}>, #<Set: {1, 3}>, #<Set: {2, 3}>, #<Set: {1, 2, 3}>}> |
||
</pre> |
|||
=={{header|SAS}}== |
|||
<lang SAS> |
|||
options mprint mlogic symbolgen source source2; |
|||
%macro SubSets (FieldCount = ); |
|||
data _NULL_; |
|||
Fields = &FieldCount; |
|||
SubSets = 2**Fields; |
|||
call symput ("NumSubSets", SubSets); |
|||
run; |
|||
%put &NumSubSets; |
|||
data inital; |
|||
%do j = 1 %to &FieldCount; |
|||
F&j. = 1; |
|||
%end; |
|||
run; |
|||
data SubSets; |
|||
set inital; |
|||
RowCount =_n_; |
|||
call symput("SetCount",RowCount); |
|||
run; |
|||
%put SetCount ; |
|||
%do %while (&SetCount < &NumSubSets); |
|||
data loop; |
|||
%do j=1 %to &FieldCount; |
|||
if rand('GAUSSIAN') > rand('GAUSSIAN') then F&j. = 1; |
|||
%end; |
|||
data SubSets_ ; |
|||
set SubSets loop; |
|||
run; |
|||
proc sort data=SubSets_ nodupkey; |
|||
by F1 - F&FieldCount.; |
|||
run; |
|||
data Subsets; |
|||
set SubSets_; |
|||
RowCount =_n_; |
|||
run; |
|||
proc sql noprint; |
|||
select max(RowCount) into :SetCount |
|||
from SubSets; |
|||
quit; |
|||
run; |
|||
%end; |
|||
%Mend SubSets; |
|||
</lang> |
|||
You can then call the macro as: |
|||
<lang SAS> |
|||
%SubSets(FieldCount = 5); |
|||
</lang> |
|||
The output will be the dataset SUBSETS and will have a 5 columns F1, F2, F3, F4, F5 and 32 columns, one with each combination of 1 and missing values. |
|||
Output: |
|||
<pre> |
|||
Obs F1 F2 F3 F4 F5 RowCount |
|||
1 . . . . . 1 |
|||
2 . . . . 1 2 |
|||
3 . . . 1 . 3 |
|||
4 . . . 1 1 4 |
|||
5 . . 1 . . 5 |
|||
6 . . 1 . 1 6 |
|||
7 . . 1 1 . 7 |
|||
8 . . 1 1 1 8 |
|||
9 . 1 . . . 9 |
|||
10 . 1 . . 1 10 |
|||
11 . 1 . 1 . 11 |
|||
12 . 1 . 1 1 12 |
|||
13 . 1 1 . . 13 |
|||
14 . 1 1 . 1 14 |
|||
15 . 1 1 1 . 15 |
|||
16 . 1 1 1 1 16 |
|||
17 1 . . . . 17 |
|||
18 1 . . . 1 18 |
|||
19 1 . . 1 . 19 |
|||
20 1 . . 1 1 20 |
|||
21 1 . 1 . . 21 |
|||
22 1 . 1 . 1 22 |
|||
23 1 . 1 1 . 23 |
|||
24 1 . 1 1 1 24 |
|||
25 1 1 . . . 25 |
|||
26 1 1 . . 1 26 |
|||
27 1 1 . 1 . 27 |
|||
28 1 1 . 1 1 28 |
|||
29 1 1 1 . . 29 |
|||
30 1 1 1 . 1 30 |
|||
31 1 1 1 1 . 31 |
|||
32 1 1 1 1 1 32 |
|||
</pre> |
</pre> |
||