Find the number of sets A such that A ⊂ {1, 2, 4, 5, 6, 8, 9, 10, 11}, |A| = 4 and A contains no consecutive integers.
There are 29:
1 4 6 8
1 4 6 9
1 4 6 10
1 4 6 11
1 4 8 10
1 4 8 11
1 4 9 11
1 5 8 10
1 5 8 11
1 5 9 11
1 6 8 10
1 6 8 11
1 6 9 11
2 4 6 8
2 4 6 9
2 4 6 10
2 4 6 11
2 4 8 10
2 4 8 11
2 4 9 11
2 5 8 10
2 5 8 11
2 5 9 11
2 6 8 10
2 6 8 11
2 6 9 11
4 6 8 10
4 6 8 11
4 6 9 11
clearvars
ct=0;
fullSet=[1 2 4 5 6 8 9 10 11];
idx=combinator(9,4,'c');
sets=fullSet(idx);
for i=1:length(sets);
set=sort(sets(i,:));
d=set(2:4)-set(1:3);
if ~ismember(1,d)
ct=ct+1;
disp(set)
end
end
ct
|
Posted by Charlie
on 2025-02-13 08:34:25 |