Cody

Problem 793. Combinations without using nchoosek

Solution 1693344

Submitted on 16 Dec 2018
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   Fail
n = 3; y_correct = nchoosek(1:n,2); assert(isequal(your_fcn_name(n),y_correct)) % Prevents cheating filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'nchoosek')))

a = 4 3 4 4 ans = 4 3 4 4

Assertion failed.

2   Fail
n = 25; y_correct = nchoosek(1:n,2); assert(isequal(your_fcn_name(n),y_correct)) filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'nchoosek')))

a = 33 32 33 33 ans = 33 32 33 33

Assertion failed.

3   Fail
n = 112; y_correct = nchoosek(1:n,2); assert(isequal(your_fcn_name(n),y_correct)) filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'nchoosek')))

Error using dec2base (line 25) Second argument must be an integer, 2 <= B <= 36. Error in your_fcn_name (line 2) a=dec2base((0:(n+1)^2-1)',n+1,2)-'0'+1; Error in Test3 (line 3) assert(isequal(your_fcn_name(n),y_correct))

4   Fail
n = 2 y_correct = nchoosek(1:n,2); assert(isequal(your_fcn_name(n),y_correct)) filetext = fileread('your_fcn_name.m') assert(isempty(strfind(filetext, 'nchoosek')))

n = 2 a = 3 2 3 3 ans = 3 2 3 3

Assertion failed.