Cody

Problem 793. Combinations without using nchoosek

Solution 1693343

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 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4

Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'. Error in your_fcn_name (line 4) [~,i]=sort( a*(10.^[1; 0])); Error in Test1 (line 3) assert(isequal(your_fcn_name(n),y_correct))

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 = Columns 1 through 30 33 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 Columns 31 through 60 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 Columns 61 through 90 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 Columns 91 through 120 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 Columns 121 through 150 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 Columns 151 through 180 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 Columns 181 through 210 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Columns 211 through 240 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 Columns 241 through 270 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 Columns 271 through 300 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 Columns 301 through 330 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 Columns 331 through 360 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 Columns 361 through 390 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Columns 391 through 420 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 Columns 421 through 450 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 Columns 451 through 480 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 Columns 481 through 510 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 Columns 511 through 540 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 Columns 541 through 570 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 Columns 571 through 600 30 31 32 33 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 Columns 601 through 630 1 2 3 4 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 Columns 631 through 660 5 6 7 8 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 1 2 3 4 5 6 7 8 Columns 661 through 678 9 10 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33

Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'. Error in your_fcn_name (line 4) [~,i]=sort( a*(10.^[1; 0])); Error in Test2 (line 3) assert(isequal(your_fcn_name(n),y_correct))

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

Error using * Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'. Error in your_fcn_name (line 4) [~,i]=sort( a*(10.^[1; 0])); Error in Test4 (line 3) assert(isequal(your_fcn_name(n),y_correct))