Effacer les filtres
Effacer les filtres

I want to insert a groups of ones in between zeros. I want to display all the possibilities.

1 vue (au cours des 30 derniers jours)
For example: 8 zeros, 6 ones (two groups with 3 in each group). Insert ones as a group in all possible places between zeros. Then i want answer as 00001110000111, 01110001110000, 00111000111000, 00011100000111. But this is a small example. But i want for a general case.

Réponse acceptée

Stephen23
Stephen23 le 21 Fév 2019
A not very efficient brute-force method:
>> C = repmat({0},1,8);
>> C(1:2) = {[1,1,1]};
>> D = num2cell(perms(1:8),2);
>> D = cellfun(@(x)[C{x}],D,'uni',0);
>> D = unique(vertcat(D{:}),'rows')
D =
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 1 1 1 0 1 1 1
0 0 0 0 0 1 1 1 1 1 1 0
0 0 0 0 1 1 1 0 0 1 1 1
0 0 0 0 1 1 1 0 1 1 1 0
0 0 0 0 1 1 1 1 1 1 0 0
0 0 0 1 1 1 0 0 0 1 1 1
0 0 0 1 1 1 0 0 1 1 1 0
0 0 0 1 1 1 0 1 1 1 0 0
0 0 0 1 1 1 1 1 1 0 0 0
0 0 1 1 1 0 0 0 0 1 1 1
0 0 1 1 1 0 0 0 1 1 1 0
0 0 1 1 1 0 0 1 1 1 0 0
0 0 1 1 1 0 1 1 1 0 0 0
0 0 1 1 1 1 1 1 0 0 0 0
0 1 1 1 0 0 0 0 0 1 1 1
0 1 1 1 0 0 0 0 1 1 1 0
0 1 1 1 0 0 0 1 1 1 0 0
0 1 1 1 0 0 1 1 1 0 0 0
0 1 1 1 0 1 1 1 0 0 0 0
0 1 1 1 1 1 1 0 0 0 0 0
1 1 1 0 0 0 0 0 0 1 1 1
1 1 1 0 0 0 0 0 1 1 1 0
1 1 1 0 0 0 0 1 1 1 0 0
1 1 1 0 0 0 1 1 1 0 0 0
1 1 1 0 0 1 1 1 0 0 0 0
1 1 1 0 1 1 1 0 0 0 0 0
1 1 1 1 1 1 0 0 0 0 0 0
  1 commentaire
SOMBABU BEJJIPURAM
SOMBABU BEJJIPURAM le 27 Fév 2019
Consider a string of length 50. Consider 20-1's and 30-zeros. Need all the possibilities of 4 groups of 5 ones (should not be placed two groups of ones together) and zeros can be placed any way. How to display all the combinations?

Connectez-vous pour commenter.

Plus de réponses (1)

Jon Wieser
Jon Wieser le 21 Fév 2019
here's a start
unique(perms([zeros(1,8),111,111]),'rows');
  1 commentaire
SOMBABU BEJJIPURAM
SOMBABU BEJJIPURAM le 21 Fév 2019
Those 3 ones are treated as a single element 111 in your answer. But in my problem they should be treated as 1,1,1.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by