Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Stephen23
Stephen23 el 21 de Feb. de 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 comentario
SOMBABU BEJJIPURAM
SOMBABU BEJJIPURAM el 27 de Feb. de 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?

Iniciar sesión para comentar.

Más respuestas (1)

Jon Wieser
Jon Wieser el 21 de Feb. de 2019
here's a start
unique(perms([zeros(1,8),111,111]),'rows');
  1 comentario
SOMBABU BEJJIPURAM
SOMBABU BEJJIPURAM el 21 de Feb. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by