Cody

Solution 539841

Submitted on 3 Dec 2014 by Binbin Qi
  • Size: 33
  • This is the leading solution.
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
%% pmin = 20; pmax = 30; d = [1 2 3 4 5]; n = [10 9 4 7 2]; p = fit_distribution(d,n,pmin,pmax) assert(~any(p<pmin) && ~any(p>pmax)) for i = 1:length(d) assert(isequal(n(i), sum(rem(p,d(i))==0))) end

ans = 21 24 28 28 28 28 28 28 30 30 p = 21 24 28 28 28 28 28 28 30 30

2   Pass
%% pmin = 1; pmax = 50; d = [1 3 5 7 8 9]; n = [40 14 12 6 4 1]; p = fit_distribution(d,n,pmin,pmax); assert(~any(p<pmin) && ~any(p>pmax)) for i = 1:length(d) assert(isequal(n(i), sum(rem(p,d(i))==0))) end

ans = Columns 1 through 16 1 1 1 1 1 1 1 1 1 1 1 1 1 1 9 39 Columns 17 through 32 39 39 42 42 42 42 42 42 48 48 48 48 50 50 50 50 Columns 33 through 40 50 50 50 50 50 50 50 50

3   Pass
%% pmin = 100; pmax = 200; d = [1 8 9 15 22]; n = [20 2 1 0 2]; p = fit_distribution(d,n,pmin,pmax); assert(~any(p<pmin) && ~any(p>pmax)) for i = 1:length(d) assert(isequal(n(i), sum(rem(p,d(i))==0))) end

ans = Columns 1 through 16 110 198 199 199 199 199 199 199 199 199 199 199 199 199 199 199 Columns 17 through 20 199 199 200 200

4   Pass
%% pmin = 5; pmax = 37; d = [1 10 20 3 11]; n = [60 7 1 19 5]; p = fit_distribution(d,n,pmin,pmax); assert(~any(p<pmin) && ~any(p>pmax)) for i = 1:length(d) assert(isequal(n(i), sum(rem(p,d(i))==0))) end

ans = Columns 1 through 16 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 Columns 17 through 32 5 5 5 5 5 5 5 5 5 5 5 5 5 6 6 6 Columns 33 through 48 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 Columns 49 through 60 10 10 10 10 10 10 11 11 11 11 11 20