Cody

# Problem 34. Binary numbers

Solution 2568276

Submitted on 16 Jun 2020 by Oliver Warlow
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
n = 2; A = binary_numbers(n); assert(isequal(class(A), 'double'))

B = 4×3 char array '001' '010' '011' '100' A = 4×2 char array '01' '10' '11' '00' A = 0 1 1 0 1 1 0 0

2   Pass
n = 3; A = binary_numbers(n); assert(all(A(:) == 0 | A(:) == 1))

B = 8×4 char array '0001' '0010' '0011' '0100' '0101' '0110' '0111' '1000' A = 8×3 char array '001' '010' '011' '100' '101' '110' '111' '000' A = 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0 1 1 1 0 0 0

3   Pass
n = 5; A = binary_numbers(n); assert(isequal(size(A),[32 5]))

B = 32×6 char array '000001' '000010' '000011' '000100' '000101' '000110' '000111' '001000' '001001' '001010' '001011' '001100' '001101' '001110' '001111' '010000' '010001' '010010' '010011' '010100' '010101' '010110' '010111' '011000' '011001' '011010' '011011' '011100' '011101' '011110' '011111' '100000' A = 32×5 char array '00001' '00010' '00011' '00100' '00101' '00110' '00111' '01000' '01001' '01010' '01011' '01100' '01101' '01110' '01111' '10000' '10001' '10010' '10011' '10100' '10101' '10110' '10111' '11000' '11001' '11010' '11011' '11100' '11101' '11110' '11111' '00000' A = 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 0 0 1 1 0 1 0 1 1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 0 0 1 1 0 0 1 0 1 0 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0 1 0 1 1 0 1 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 1 1 1 0 0 0 0 0

4   Pass
n = 10; A = binary_numbers(n); assert(isequal(size(unique(A,'rows'),1),1024))

B = 1024×11 char array '00000000001' '00000000010' '00000000011' '00000000100' '00000000101' '00000000110' '00000000111' '00000001000' '00000001001' '00000001010' '00000001011' '00000001100' '00000001101' '00000001110' '00000001111' '00000010000' '00000010001' '00000010010' '00000010011' '00000010100' '00000010101' '00000010110' '00000010111' '00000011000' '00000011001' '00000011010' '00000011011' '00000011100' '00000011101' '00000011110' '00000011111' '00000100000' '00000100001' '00000100010' '00000100011' '00000100100' '00000100101' '00000100110' '00000100111' '00000101000' '00000101001' '00000101010' '00000101011' '00000101100' '00000101101' '00000101110' '00000101111' '00000110000' '00000110001' '00000110010' '00000110011' '00000110100' '00000110101' '00000110110' '00000110111' '00000111000' '00000111001' '00000111010' '00000111011' '00000111100' '00000111101' '00000111110' '00000111111' '00001000000' '00001000001' '00001000010' '00001000011' '00001000100' '00001000101' '00001000110' '00001000111' '00001001000' '00001001001' '00001001010' '00001001011' '00001001100' '00001001101' '00001001110' '00001001111' '00001010000' '00001010001' '00001010010' '00001010011' '00001010100' '00001010101' '00001010110' '00001010111' '00001011000' '00001011001' '00001011010' '00001011011' '00001011100' '00001011101' '00001011110' '00001011111' '00001100000' '00001100001' '00001100010' '00001100011' '00001100100' '00001100101' '00001100110' '00001100111' '00001101000' '00001101001' '00001101010' '00001101011' '00001101100' '00001101101' '00001101110' '00001101111' '00001110000' '00001110001' '00001110010' '00001110011' '00001110100' '00001110101' '00001110110' '00001110111' '00001111000' '00001111001' '00001111010' '00001111011' '00001111100' '00001111101' '00001111110' '00001111111' '00010000000' '00010000001' '00010000010' '00010000011' '00010000100' '00010000101' '00010000110' '00010000111' '00010001000' '00010001001' '00010001010' '00010001011' '00010001100' '00010001101' '00010001110' '00010001111' '00010010000' '00010010001' '00010010010' '00010010011' '00010010100' '00010010101' '00010010110' '00010010111' '00010011000' '00010011001' '00010011010' '00010011011' '00010011100' '00010011101' '00010011110' '00010011111' '00010100000' '00010100001' '00010100010' '00010100011' '00010100100' '00010100101' '00010100110' '00010100111' '00010101000' '00010101001' '00010101010' '00010101011' '00010101100' '00010101101' '00010101110' '00010101111' '00010110000' '00010110001' '00010110010' '00010110011' '00010110100' '00010110101' '00010110110' '00010110111' '00010111000' '00010111001' '00010111010' '00010111011' '00010111100' '00010111101' '00010111110' '00010111111' '00011000000' '00011000001' '00011000010' '00011000011' '00011000100' '00011000101' '00011000110' '00011000111' '00011001000' '00011001001' '00011001010' '00011001011' '00011001100' '00011001101' '00011001110' '00011001111' '00011010000' '00011010001' '00011010010' '00011010011' '00011010100' '00011010101' '00011010110' '00011010111' '00011011000' '00011011001' '00011011010' '00011011011' '00011011100' '00011011101' '00011011110' '00011011111' '00011100000' '00011100001' '00011100010' '00011100011' '00011100100' '00011100101' '00011100110' '00011100111' '00011101000' '00011101001' '00011101010' '00011101011' '00011101100' '00011101101' '00011101110' '00011101111' '00011110000' '00011110001' '00011110010' '00011110011' '00011110100' '00011110101' '00011110110' '00011110111' '00011111000' '00011111001' '00011111010' '00011111011' '00011111100' '00011111101' '00011111110' '00011111111' '00100000000' '00100000001' '00100000010' '00100000011' '00100000100' '00100000101' '00100000110' '00100000111' '00100001000' '00100001001' '00100001010' '00100001011' '00100001100' '00100001101' '00100001110' '00100001111' '00100010000' '00100010001' '00100010010' '00100010011' '00100010100' '00100010101' '00100010110' '00100010111' '00100011000' '00100011001' '00100011010' '00100011011' '00100011100' '00100011101' '00100011110' '00100011111' '00100100000' '00100100001' '00100100010' '00100100011' '00100100100' '00100100101' '00100100110' '00100100111' '00100101000' '00100101001' '00100101010' '00100101011' '00100101100' '00100101101' '00100101110' '00100101111' '00100110000' '00100110001' '00100110010' '00100110011' '00100110100' '00100110101' '00100110110' '00100110111' '00100111000' '00100111001' '00100111010' '00100111011' '00100111100' '00100111101' '00100111110' '00100111111' '00101000000' '00101000001' '00101000010' '00101000011' '00101000100' '00101000101' '00101000110' '00101000111' '00101001000' '00101001001' '00101001010' '00101001011' '00101001100' '00101001101' '00101001110' '00101001111' '00101010000' '00101010001' '00101010010' '00101010011' '00101010100' '00101010101' '00101010110' '00101010111' '00101011000' '00101011001' '00101011010' '00101011011' '00101011100' '00101011101' '00101011110' '00101011111' '00101100000' '00101100001' '00101100010' '00101100011' '00101100100' '00101100101' '00101100110' '00101100111' '00101101000' '00101101001' '00101101010' '00101101011' '00101101100' '00101101101' '00101101110' '00101101111' '00101110000' '00101110001' '00101110010' '00101110011' '00101110100' '00101110101' '00101110110' '00101110111' '00101111000' '00101111001' '00101111010' '00101111011' '00101111100' '00101111101' '00101111110' '00101111111' '00110000000' '00110000001' '00110000010' '00110000011' '00110000100' '00110000101' '00110000110' '00110000111' '00110001000' '00110001001' '00110001010' '00110001011' '00110001100' '00110001101' '00110001110' '00110001111' '00110010000' '00110010001' '00110010010' '00110010011' '00110010100' '00110010101' '00110010110' '00110010111' '00110011000' '00110011001' '00110011010' '00110011011' '00110011100' '00110011101' '00110011110' '00110011111' '00110100000' '00110100001' '00110100010' '00110100011' '00110100100' '00110100101' '00110100110' '00110100111' '00110101000' '00110101001' '00110101010' '00110101011' '00110101100' '00110101101' '00110101110' '00110101111' '00110110000' '00110110001' '00110110010' '00110110011' '00110110100' '00110110101' '00110110110' '00110110111' '00110111000' '00110111001' '00110111010' '00110111011' '00110111100' '00110111101' '00110111110' '00110111111' '00111000000' '00111000001' '00111000010' '00111000011' '00111000100' '00111000101' '00111000110' '00111000111' '00111001000' '00111001001' '00111001010' '00111001011' '00111001100' '00111001101' '00111001110' '00111001111' '00111010000' '00111010001' '00111010010' '00111010011' '00111010100' '00111010101' '00111010110' '00111010111' '00111011000' '00111011001' '00111011010' '00111011011' '00111011100' '00111011101' '00111011110' '00111011111' '00111100000' '00111100001' '00111100010' '00111100011' '00111100100' '00111100101' '00111100110' '00111100111' '00111101000' '00111101001' '00111101010' '00111101011' '00111101100' '00111101101' '00111101110' '00111101111' '00111110000' '00111110001' '00111110010' '00111110011' '00111110100' '00111110101' '00111110110' '00111110111' '00111111000' '00111111001' '00111111010' '00111111011' '00111111100' '00111111101' '00111111110' '00111111111' '01000000000' '01000000001' '01000000010' '01000000011' '01000000100' '01000000101' '01000000110' '01000000111' '01000001000' '01000001001' '01000001010' '01000001011' '01000001100' '01000001101' '01000001110' '01000001111' '01000010000' '01000010001' '01000010010' '01000010011' '01000010100' '01000010101' '01000010110' '01000010111' '01000011000' '01000011001' '01000011010' '01000011011' '01000011100' '01000011101' '01000011110' '01000011111' '01000100000' '01000100001' '01000100010' '01000100011' '01000100100' '01000100101' '01000100110' '01000100111' '01000101000' '01000101001' '01000101010' ...

5   Pass
n = 1; A = binary_numbers(n); assert(isequal(A,[0;1]) || isequal(A,[1;0]))

B = 2×2 char array '01' '10' A = 2×1 char array '1' '0' A = 1 0

### Community Treasure Hunt

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

Start Hunting!