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!!
when n = 3;
A = binary_numbers(n);
assert(all(A(:) == 0 | A(:) == 1))
Very fun problem!
B = repmat([0 1],1,n);
A = unique(nchoosek(B,n),'rows');
easy but made me think. nice problem
i can solve it but i have a small mistake
de2bi() function is not working for this code. Solves the problem when you run it on MATLAB
I correct my comments in the source code.
It was 'Column', not 'Row'.
'Column 1 is 0 1 0 1 ..., column 2 is 0 0 1 1 ... , continue to column n.'
got me one more hour to solve this
In the third test i.e, for n=5, shouldn't the size (A) be compared to [31 5] instead of [32 5] ?
I didn't even tried to do that, but yeah in example it's 8x3 ( n^2-1 x n) matrix but then it asks 32x5 for n=5 ... quite odd
Undefined function 'de2bi' for input arguments of type 'double'...
de2bi is part of the 'Communications System Toolbox'
I've just solved this problem by the code that "A=(dec2bin(0:2^n-1)-48);" How it could be that the size of leading solution is 9,but mine is 21 !?
could you pls explain the "-48" to me? i see what it does, but dont know why...
There is a regexp() trick that some people use to produce very small sized answers. However, they do not necessarily produce a correct solution to the real world problem. I tend to proud that my answers correctly solve the problem, regardless of their size. It is a shame that the regexp() exploit is not discouraged.
When using a numerical operator against a character vector, MATLAB interprets the char-vec as a numerical vector with values that correspond to the ASCII values. As such, the ASCII values can be passed through the char() function to produce the original char-vec. i.e. ---> char('Some Text'+1) = 'Some Text'
The test suite is poorly designed. A better test would be
Why is it not possible to use de2bi?
One ugly line
Can anybody please explain the size ???? I just wrote 1 line !!!
Whats wrong in this ?
Worst Solution ever!!^^
function ans = binary_numbers(n)
end test suit 2 3 fails bit 1 4 5 pass help me
function A = binary_numbers(n)
A = dec2bin(0:2^n-1);
This should give the correct solution, but fails in the Test Suite!!!
Not sure about tests 2 and 5, but test 1 requires a type 'double' answer. Your code returns a type 'logical' answer.
Cant able to understand the problem. Please explain me
how can you come up with such a sotlution,l thought for a long time,still have no shorter solution
The test suite for this solution does not seem to work properly.
Error: Undefined function 'ff2n' for input arguments of type 'double'.
Use of ff2n is no longer allowed; we are not competing in the same league as the first contestants
I have never seen 'ans' used this way before!
why not this function ff2n?
They should disallow toolbox functions... this one doesn't work for me!
good answer function!
How did you get the idea?
I mean it's certainly short... but pretty inefficient...
what does the 'size' mean? It's ridiculous :)
@Jean-Yves, having arrived at the same idea, it is from #4 in the test suite for this problem.
radius of a spherical planet
Is this matrix orthogonal?
Matrix with different incremental runs
Symmetry of vector
Get the area codes from a list of phone numbers
Find the palindrome
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office