Problem 42918. Addition Partition

Solution 2158048

Submitted on 12 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
N=5;K=3; assert(isequal(num_sum(N,K),5))

2   Pass
N=7;K=4; assert(isequal(num_sum(N,K),11))

3   Pass
N=7;K=3; assert(isequal(num_sum(N,K),8))

4   Pass
N=15;K=6; assert(isequal(num_sum(N,K),110))

5   Pass
N=20;K=4; assert(isequal(num_sum(N,K),108))

6   Fail
N=12;K=9; assert(isequal(num_sum(N,K),73))

Error using repmat Requested 13x13x13x13x13x13x13x13x13 (79.0GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in ndgrid (line 72) varargout{i} = repmat(x,s); Error in num_sum>permn (line 45) [Y{N:-1:1}] = ndgrid(1:nV) ; Error in num_sum (line 13) s=permn(0:N,K); Error in Test6 (line 2) assert(isequal(num_sum(N,K),73))

7   Pass
N=13;K=3; assert(isequal(num_sum(N,K),21))

8   Pass
N=12;K=2; assert(isequal(num_sum(N,K),7))

9   Pass
N=15;K=2; assert(isequal(num_sum(N,K),8))