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

1 view (last 30 days)
SOMBABU BEJJIPURAM on 21 Feb 2019
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.

Stephen on 21 Feb 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
SOMBABU BEJJIPURAM on 27 Feb 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?

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