Cody

Problem 1287. Unique dice configurations

Solution 2173250

Submitted on 24 Mar 2020
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   Pass
assert(isequal(unique_dice(2,6),21))

configs = 21

2   Pass
assert(isequal(unique_dice(6,8),1716))

configs = 1716

3   Pass
assert(isequal(unique_dice(10,12),352716))

configs = 352716

4   Pass
assert(isequal(unique_dice(20,20),68923264410))

configs = 6.8923e+10

5   Pass
assert(isequal(unique_dice(4,100),4421275))

configs = 4421275

6   Pass
assert(isequal(unique_dice(100,4),176851))

configs = 176851

7   Fail
x=ceil(10000*rand); assert(isequal(unique_dice(1,x),x))

Error using nchoosek (line 29) The second input has to be a non-negative integer. Error in unique_dice>@(i)(S-i+1)*nchoosek(i+N-3,N-2) (line 9) configs=sum(arrayfun(@(i) (S-i+1)*nchoosek(i+N-3, N-2), 1:S)) Error in unique_dice (line 9) configs=sum(arrayfun(@(i) (S-i+1)*nchoosek(i+N-3, N-2), 1:S)) Error in Test7 (line 2) assert(isequal(unique_dice(1,x),x))