tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
18
Task/Power-set/MATLAB/power-set-1.m
Normal file
18
Task/Power-set/MATLAB/power-set-1.m
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function pset = powerset(theSet)
|
||||
|
||||
pset = cell(size(theSet)); %Preallocate memory
|
||||
|
||||
%Generate all numbers from 0 to 2^(num elements of the set)-1
|
||||
for i = ( 0:(2^numel(theSet))-1 )
|
||||
|
||||
%Convert i into binary, convert each digit in binary to a boolean
|
||||
%and store that array of booleans
|
||||
indicies = logical(bitget( i,(1:numel(theSet)) ));
|
||||
|
||||
%Use the array of booleans to extract the members of the original
|
||||
%set, and store the set containing these members in the powerset
|
||||
pset(i+1) = {theSet(indicies)};
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
5
Task/Power-set/MATLAB/power-set-2.m
Normal file
5
Task/Power-set/MATLAB/power-set-2.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
powerset({{}})
|
||||
|
||||
ans =
|
||||
|
||||
{} {1x1 cell} %This is the same as { {},{{}} }
|
||||
5
Task/Power-set/MATLAB/power-set-3.m
Normal file
5
Task/Power-set/MATLAB/power-set-3.m
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
powerset({{1,2},3})
|
||||
|
||||
ans =
|
||||
|
||||
{1x0 cell} {1x1 cell} {1x1 cell} {1x2 cell} %This is the same as { {},{{1,2}},{3},{{1,2},3} }
|
||||
Loading…
Add table
Add a link
Reference in a new issue