Cody

Problem 34. Binary numbers

Solution 1040968

Submitted on 31 Oct 2016 by Jakub Mrowka
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'))

x1 = 0 c1 = 0 0 x1 = 1 c1 = 0 1 x1 = 2 c1 = 1 0 x1 = 3 c1 = 1 1

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

x1 = 0 c1 = 0 0 0 x1 = 1 c1 = 0 0 1 x1 = 2 c1 = 0 1 0 x1 = 3 c1 = 0 1 1 x1 = 4 c1 = 1 0 0 x1 = 5 c1 = 1 0 1 x1 = 6 c1 = 1 1 0 x1 = 7 c1 = 1 1 1

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

x1 = 0 c1 = 0 0 0 0 0 x1 = 1 c1 = 0 0 0 0 1 x1 = 2 c1 = 0 0 0 1 0 x1 = 3 c1 = 0 0 0 1 1 x1 = 4 c1 = 0 0 1 0 0 x1 = 5 c1 = 0 0 1 0 1 x1 = 6 c1 = 0 0 1 1 0 x1 = 7 c1 = 0 0 1 1 1 x1 = 8 c1 = 0 1 0 0 0 x1 = 9 c1 = 0 1 0 0 1 x1 = 10 c1 = 0 1 0 1 0 x1 = 11 c1 = 0 1 0 1 1 x1 = 12 c1 = 0 1 1 0 0 x1 = 13 c1 = 0 1 1 0 1 x1 = 14 c1 = 0 1 1 1 0 x1 = 15 c1 = 0 1 1 1 1 x1 = 16 c1 = 1 0 0 0 0 x1 = 17 c1 = 1 0 0 0 1 x1 = 18 c1 = 1 0 0 1 0 x1 = 19 c1 = 1 0 0 1 1 x1 = 20 c1 = 1 0 1 0 0 x1 = 21 c1 = 1 0 1 0 1 x1 = 22 c1 = 1 0 1 1 0 x1 = 23 c1 = 1 0 1 1 1 x1 = 24 c1 = 1 1 0 0 0 x1 = 25 c1 = 1 1 0 0 1 x1 = 26 c1 = 1 1 0 1 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1 = 91 c1 = 0 0 0 1 0 1 1 0 1 1 x1 = 92 c1 = 0 0 0 1 0 1 1 1 0 0 x1 = 93 c1 = 0 0 0 1 0 1 1 1 0 1 x1 = 94 c1 = 0 0 0 1 0 1 1 1 1 0 x1 = 95 c1 = 0 0 0 1 0 1 1 1 1 1 x1 = 96 c1 = 0 0 0 1 1 0 0 0 0 0 x1 = 97 c1 = 0 0 0 1 1 0 0 0 0 1 x1 = 98 c1 = 0 0 0 1 1 0 0 0 1 0 x1 = 99 c1 = 0 0 0 1 1 0 0 0 1 1 x1 = 100 c1 = 0 0 0 1 1 0 0 1 0 0 x1 = 101 c1 = 0 0 0 1 1 0 0 1 0 1 x1 = 102 c1 = 0 0 0 1 1 0 0 1 1 0 x1 = 103 c1 = 0 0 0 1 1 0 0 1 1 1 x1 = 104 c1 = 0 0 0 1 1 0 1 0 0 0 x1 = 105 c1 = 0 0 0 1 1 0 1 0 0 1 x1 = 106 c1 = 0 0 0 1 1 0 1 0 1 0 x1 = 107 c1 = 0 0 0 1 1 0 1 0 1 1 x1 = 108 c1 = 0 0 0 1 1 0 1 1 0 0 x1 = 109 c1 = 0 0 0 1 1 0 1 1 0 1 x1 = 110 c1 = 0 0 0 1 1 0 1 1 1 0 x1 = 111 c1 = 0 0 0 1 1 0 1 1 1 1 x1 = 112 c1 = 0 0 0 1 1 1 0 0 0 0 x1 = 113 c1 = 0 0 0 1 1 1 0 0 0 1 x1 = 114 c1 = 0 0 0 1 1 1 0 0 1 0 x1 = 115 c1 = 0 0 0 1 1 1 0 0 1 1 x1 = 116 c1 = 0 0 0 1 1 1 0 1 0 0 x1 = 117 c1 = 0 0 0 1 1 1 0 1 0 1 x1 = 118 c1 = 0 0 0 1 1 1 0 1 1 0 x1 =...

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

x1 = 0 c1 = 0 x1 = 1 c1 = 1

Community Treasure Hunt

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

Start Hunting!