Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 80368

Submitted on 22 Apr 2012 by Freddy

Correct

139Size
Leading solution size is 33.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
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
n =
     9
     8
     4
     6
     1
n =
     8
     7
     4
     5
     0
n =
     7
     6
     3
     4
     0
n =
     6
     5
     2
     3
     0
n =
     5
     4
     1
     2
     0
n =
     4
     3
     0
     1
     0
n =
     3
     2
     0
     0
     0
n =
     2
     1
     0
     0
     0
n =
     1
     0
     0
     0
     0
n =
     0
     0
     0
     0
     0
p =
    20    20    24    24    24    24    28    22    22    23
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
n =
    39
    13
    11
     6
     4
     0
n =
    38
    12
    10
     6
     4
     0
n =
    37
    11
     9
     6
     4
     0
n =
    36
    10
     8
     6
     4
     0
n =
    35
     9
     7
     6
     4
     0
n =
    34
     8
     6
     6
     4
     0
n =
    33
     7
     5
     6
     4
     0
n =
    32
     6
     4
     6
     4
     0
n =
    31
     5
     3
     6
     4
     0
n =
    30
     4
     2
     6
     4
     0
n =
    29
     3
     1
     6
     4
     0
n =
    28
     2
     0
     6
     4
     0
n =
    27
     1
     0
     5
     4
     0
n =
    26
     0
     0
     4
     4
     0
n =
    25
     0
     0
     3
     4
     0
n =
    24
     0
     0
     2
     4
     0
n =
    23
     0
     0
     1
     4
     0
n =
    22
     0
     0
     0
     4
     0
n =
    21
     0
     0
     0
     3
     0
n =
    20
     0
     0
     0
     2
     0
n =
    19
     0
     0
     0
     1
     0
n =
    18
     0
     0
     0
     0
     0
n =
    17
     0
     0
     0
     0
     0
n =
    16
     0
     0
     0
     0
     0
n =
    15
     0
     0
     0
     0
     0
n =
    14
     0
     0
     0
     0
     0
n =
    13
     0
     0
     0
     0
     0
n =
    12
     0
     0
     0
     0
     0
n =
    11
     0
     0
     0
     0
     0
n =
    10
     0
     0
     0
     0
     0
n =
     9
     0
     0
     0
     0
     0
n =
     8
     0
     0
     0
     0
     0
n =
     7
     0
     0
     0
     0
     0
n =
     6
     0
     0
     0
     0
     0
n =
     5
     0
     0
     0
     0
     0
n =
     4
     0
     0
     0
     0
     0
n =
     3
     0
     0
     0
     0
     0
n =
     2
     0
     0
     0
     0
     0
n =
     1
     0
     0
     0
     0
     0
n =
     0
     0
     0
     0
     0
     0
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
n =
    19
     1
     0
     2
n =
    18
     0
     0
     1
n =
    17
     0
     0
     0
n =
    16
     0
     0
     0
n =
    15
     0
     0
     0
n =
    14
     0
     0
     0
n =
    13
     0
     0
     0
n =
    12
     0
     0
     0
n =
    11
     0
     0
     0
n =
    10
     0
     0
     0
n =
     9
     0
     0
     0
n =
     8
     0
     0
     0
n =
     7
     0
     0
     0
n =
     6
     0
     0
     0
n =
     5
     0
     0
     0
n =
     4
     0
     0
     0
n =
     3
     0
     0
     0
n =
     2
     0
     0
     0
n =
     1
     0
     0
     0
n =
     0
     0
     0
     0
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
n =
    59
     6
     0
    19
     5
n =
    58
     5
     0
    18
     5
n =
    57
     4
     0
    17
     5
n =
    56
     3
     0
    16
     5
n =
    55
     2
     0
    15
     5
n =
    54
     1
     0
    14
     5
n =
    53
     0
     0
    13
     5
n =
    52
     0
     0
    12
     4
n =
    51
     0
     0
    11
     3
n =
    50
     0
     0
    10
     2
n =
    49
     0
     0
     9
     1
n =
    48
     0
     0
     8
     0
n =
    47
     0
     0
     7
     0
n =
    46
     0
     0
     6
     0
n =
    45
     0
     0
     5
     0
n =
    44
     0
     0
     4
     0
n =
    43
     0
     0
     3
     0
n =
    42
     0
     0
     2
     0
n =
    41
     0
     0
     1
     0
n =
    40
     0
     0
     0
     0
n =
    39
     0
     0
     0
     0
n =
    38
     0
     0
     0
     0
n =
    37
     0
     0
     0
     0
n =
    36
     0
     0
     0
     0
n =
    35
     0
     0
     0
     0
n =
    34
     0
     0
     0
     0
n =
    33
     0
     0
     0
     0
n =
    32
     0
     0
     0
     0
n =
    31
     0
     0
     0
     0
n =
    30
     0
     0
     0
     0
n =
    29
     0
     0
     0
     0
n =
    28
     0
     0
     0
     0
n =
    27
     0
     0
     0
     0
n =
    26
     0
     0
     0
     0
n =
    25
     0
     0
     0
     0
n =
    24
     0
     0
     0
     0
n =
    23
     0
     0
     0
     0
n =
    22
     0
     0
     0
     0
n =
    21
     0
     0
     0
     0
n =
    20
     0
     0
     0
     0
n =
    19
     0
     0
     0
     0
n =
    18
     0
     0
     0
     0
n =
    17
     0
     0
     0
     0
n =
    16
     0
     0
     0
     0
n =
    15
     0
     0
     0
     0
n =
    14
     0
     0
     0
     0
n =
    13
     0
     0
     0
     0
n =
    12
     0
     0
     0
     0
n =
    11
     0
     0
     0
     0
n =
    10
     0
     0
     0
     0
n =
     9
     0
     0
     0
     0
n =
     8
     0
     0
     0
     0
n =
     7
     0
     0
     0
     0
n =
     6
     0
     0
     0
     0
n =
     5
     0
     0
     0
     0
n =
     4
     0
     0
     0
     0
n =
     3
     0
     0
     0
     0
n =
     2
     0
     0
     0
     0
n =
     1
     0
     0
     0
     0
n =
     0
     0
     0
     0
     0