Given a positive, scalar integer n, create a (2^n)-by-n double-precision matrix containing the binary numbers from 0 through 2^n-1. Each row of the matrix represents one binary number. For example, if n = 3, then your code could return
>> binary_numbers(3)
ans =
1 1 1
0 0 0
0 1 1
0 1 0
0 0 1
1 0 0
1 1 0
1 0 1The order of the rows does not matter.
Solution Stats
Problem Comments
11 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers4774
Suggested Problems
-
27589 Solvers
-
Sort a list of complex numbers based on far they are from the origin.
5797 Solvers
-
10709 Solvers
-
Project Euler: Problem 5, Smallest multiple
1649 Solvers
-
Set the array elements whose value is 13 to 0
1438 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
matlab functions should not be allowed. Let people think of the solution from scratch.
I actually use a function to do this in my project, but my original code scored 47.
I had all the test cases working properly except for n=10!
This is very weird!!
what's meaning?
when n = 3;
A = binary_numbers(n);
assert(all(A(:) == 0 | A(:) == 1))
fun!
Very fun problem!
More difficult than I expected!
There was a guy who solved this problem with around 11k code size. Absolute madlad.
Fun exercise!
difficult that I intended it to be.
Wait until you see the guy who solved it with a +41k code size.