Cody

Problem 793. Combinations without using nchoosek

Solution 1693338

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')))

ans = 4 4 4 3 4 2 4 1 3 4 3 3 3 2 3 1 2 4 2 3 2 2 2 1 1 4 1 3 1 2 1 1

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')))

ans = 33 33 33 32 33 31 33 30 33 29 33 28 33 27 33 26 33 25 33 24 32 33 33 23 32 32 33 22 32 31 33 21 32 30 33 20 32 29 33 19 32 28 33 18 32 27 32 26 32 25 32 24 31 33 32 23 31 32 32 22 31 31 32 21 31 30 32 20 33 10 31 29 32 19 33 9 31 28 32 18 33 8 31 27 33 7 31 26 33 6 31 25 33 5 31 24 33 4 30 33 31 23 33 3 30 32 31 22 33 2 30 31 31 21 33 1 30 30 31 20 32 10 30 29 31 19 32 9 30 28 31 18 32 8 30 27 32 7 30 26 32 6 30 25 32 5 30 24 32 4 29 33 30 23 32 3 29 32 30 22 32 2 29 31 30 21 32 1 29 30 30 20 31 10 29 29 30 19 31 9 29 28 30 18 31 8 29 27 31 7 29 26 31 6 29 25 31 5 29 24 31 4 28 33 29 23 31 3 28 32 29 22 31 2 28 31 29 21 31 1 28 30 29 20 30 10 28 29 29 19 30 9 28 28 29 18 30 8 28 27 30 7 28 26 30 6 28 25 30 5 28 24 30 4 27 33 28 23 30 3 27 32 28 22 30 2 27 31 28 21 30 1 27 30 28 20 29 10 27 29 28 19 29 9 27 28 28 18 29 8 27 27 29 7 27 26 29 6 27 25 29 5 27 24 29 4 26 33 27 23 29 3 26 32 27 22 29 2 26 31 27 21 29 1 26 30 27 20 28 10 26 29 27 19 28 9 26 28 27 18 28 8 26 27 28 7 26 26 28 6 26 25 28 5 26 24 28 4 25 33 26 23 28 3 25 32 26 22 28 2 25 31 26 21 28 1 25 30 26 20 27 10 25 29 26 19 27 9 25 28 26 18 27 8 25 27 27 7 25 26 27 6 25 25 27 5 25 24 27 4 24 33 25 23 27 3 24 32 25 22 27 2 24 31 25 21 27 1 24 30 25 20 26 10 24 29 25 19 26 9 24 28 25 18 26 8 24 27 26 7 24 26 26 6 24 25 26 5 24 24 26 4 23 33 24 23 26 3 23 32 24 22 26 2 23 31 24 21 26 1 23 30 24 20 25 10 23 29 24 19 25 9 23 28 24 18 25 8 23 27 25 7 23 26 25 6 23 25 25 5 23 24 25 4 22 33 23 23 25 3 22 32 23 22 25 2 22 31 23 21 25 1 22 30 23 20 24 10 22 29 23 19 24 9 22 28 23 18 24 8 22 27 24 7 22 26 24 6 22 25 24 5 22 24 24 4 21 33 22 23 24 3 21 32 22 22 24 2 21 31 22 21 24 1 21 30 22 20 23 10 21 29 22 19 23 9 21 28 22 18 23 8 21 27 23 7 21 26 23 6 21 25 23 5 21 24 23 4 20 33 21 23 23 3 20 32 21 22 23 2 20 31 21 21 23 1 20 30 21 20 22 10 20 29 21 19 22 9 20 28 21 18 22 8 20 27 22 7 20 26 22 6 20 25 22 5 20 24 22 4 19 33 20 23 22 3 19 32 20 22 22 2 19 31 20 21 22 1 19 30 20 20 21 10 19 29 20 19 21 9 19 28 20 18 21 8 19 27 21 7 19 26 21 6 19 25 21 5 19 24 21 4 18 33 19 23 21 3 18 32 19 22 21 2 18 31 19 21 21 1 18 30 19 20 20 10 18 29 19 19 20 9 18 28 19 18 20 8 18 27 20 7 18 26 20 6 18 25 20 5 18 24 20 4 18 23 20 3 18 22 20 2 18 21 20 1 18 20 19 10 18 19 19 9 18 18 19 8 19 7 19 6 19 5 19 4 19 3 19 2 19 1 18 10 18 9 18 8 18 7 18 6 18 5 18 4 18 3 18 2 18 1 10 33 10 32 10 31 10 30 10 29 10 28 10 27 10 26 10 25 10 24 9 33 10 23 9 32 10 22 9 31 10 21 9 30 10 20 9 29 10 19 9 28 10 18 9 27 9 26 9 25 9 24 8 33 9 23 8 32 9 22 8 31 9 21 8 30 9 20 10 10 8 29 9 19 10 9 8 28 9 18 10 8 8 27 10 7 8 26 10 6 8 25 10 5 8 24 10 4 7 33 8 23 10 3 7 32 8 22 10 2 7 31 8 21 10 1 7 30 8 20 9 10 7 29 8 19 9 9 7 28 8 18 9 8 7 27 9 7 7 26 9 6 7 25 9 5 7 24 9 4 6 33 7 23 9 3 6 32 7 22 9 2 6 31 7 21 9 1 6 30 7 20 8 10 6 29 7 19 8 9 6 28 7 18 8 8 6 27 8 7 6 26 8 6 6 25 8 5 6 24 8 4 5 33 6 23 8 3 5 32 6 22 8 2 5 31 6 21 8 1 5 30 6 20 7 10 5 29 6 19 7 9 5 28 6 18 7 8 5 27 7 7 5 26 7 6 5 25 7 5 5 24 7 4 4 33 5 23 7 3 4 32 5 22 7 2 4 31 5 21 7 1 4 30 5 20 6 10 4 29 5 19 6 9 4 28 5 18 6 8 4 27 6 7 4 26 6 6 4 25 6 5 4 24 6 4 3 33 4 23 6 3 3 32 4 22 6 2 3 31 4 21 6 1 3 30 4 20 5 10 3 29 4 19 5 9 3 28 4 18 5 8 3 27 5 7 3 26 5 6 3 25 5 5 3 24 5 4 2 33 3 23 5 3 2 32 3 22 5 2 2 31 3 21 5 1 2 30 3 20 4 10 2 29 3 19 4 9 2 28 3 18 4 8 2 27 4 7 2 26 4 6 2 25 4 5 2 24 4 4 1 33 2 23 4 3 1 32 2 22 4 2 1 31 2 21 4 1 1 30 2 20 3 10 1 29 2 19 3 9 1 28 2 18 3 8 1 27 3 7 1 26 3 6 1 25 3 5 1 24 3 4 1 23 3 3 1 22 3 2 1 21 3 1 1 20 2 10 1 19 2 9 1 18 2 8 2 7 2 6 2 5 2 4 2 3 2 2 2 1 1 10 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 1

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 ans = 3 3 3 2 3 1 2 3 2 2 2 1 1 3 1 2 1 1

Assertion failed.

Suggested Problems

More from this Author30

Community Treasure Hunt

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

Start Hunting!