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

조회 수: 1 (최근 30일)
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.

채택된 답변

Stephen23
Stephen23 2019년 2월 21일
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
SOMBABU BEJJIPURAM
SOMBABU BEJJIPURAM 2019년 2월 27일
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?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Jon Wieser
Jon Wieser 2019년 2월 21일
here's a start
unique(perms([zeros(1,8),111,111]),'rows');
  댓글 수: 1
SOMBABU BEJJIPURAM
SOMBABU BEJJIPURAM 2019년 2월 21일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by