Cody

# Problem 1488. Generate binary combinations for a given number of bit(s)

Solution 1040356

Submitted on 31 Oct 2016 by Jakub Rysanek
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
bits = 1; y_correct = [0; 1]; assert(isequal(bin_comb(bits),y_correct))

nnn = cell {1×1 cell} nnn = cell {1×1 cell}

2   Pass
bits = 2; y_correct = [0 0;0 1; 1 0; 1 1] assert(isequal(bin_comb(bits),y_correct))

y_correct = 0 0 0 1 1 0 1 1 nnn = cell {1×2 cell} nnn = cell {1×2 cell} nnn = cell {1×2 cell} nnn = cell {1×2 cell}

3   Pass
bits = 3; y_correct = [0 0 0;0 0 1;0 1 0;0 1 1;1 0 0; 1 0 1; 1 1 0; 1 1 1] assert(isequal(bin_comb(bits),y_correct))

y_correct = 0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 nnn = cell {1×3 cell} nnn = cell {1×3 cell} nnn = cell {1×3 cell} nnn = cell {1×3 cell} nnn = cell {1×3 cell} nnn = cell {1×3 cell} nnn = cell {1×3 cell} nnn = cell {1×3 cell}