For inputs n and k (in that order), output the number of ways that k objects can be chosen from amongst n distinct objects. [The order of the selected objects is irrelevant.]
For example, suppose you have 4 blocks: red, green, blue, yellow. How many ways are there to select 2 of them? There are 6 ways: RG, RB, RY, GB, GY, BY. [Remember the ordering is irrelevant, so GR is equivalent to RG, and therefore does not count as a distinct choice.]
So, function(4,2) ---> 6.
Why in my pc showing correct but not in this
@Sumit, you are probably using a function from a toolbox (e.g. statistics toolbox) that is not available to Cody.
http://onlinestatbook.com/2/probability/permutations.html
The test suite throws errors where but I get correct answers when I run.
function y = fcn(n,k)
y = size(combntns(1:n,k),1);
end
Let me import my Statistics Toolbox!
;)
152 Solvers
Find perfect placement of non-rotating dominoes (easier)
228 Solvers
Return unique values without sorting
486 Solvers
Create a vector whose elements depend on the previous element
290 Solvers
Sum the numbers on the main diagonal
375 Solvers