Cody

# Problem 1516. Put m balls into n boxes

Solution 1690249

Submitted on 11 Dec 2018 by Augusto Mazzei
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
m = 3; n = 2; y_correct = [ 1 1 1 1 1 2 1 2 2 2 2 2]; assert(isequal(putintoballs(m,n),y_correct))

i = 3 mn = 1 1 1 1 1 2 1 2 3 mn = 1 1 1 1 1 2 1 2 2 i = 3 mn = 1 1 1 1 1 2 1 2 2 1 3 3 mn = 1 1 1 1 1 2 1 2 2 1 3 3 i = 2 3 mn = 1 1 1 1 1 2 1 2 2 2 3 3 mn = 1 1 1 1 1 2 1 2 2 2 2 2 1 1 1 1 1 2 1 2 2 2 2 2

2   Pass
filetext = fileread('putintoballs.m'); assert(isempty(strfind(filetext, 'fopen'))); assert(isempty(strfind(filetext, 'assert'))); assert(isempty(strfind(filetext, 'regexp'))); assert(isempty(strfind(filetext, 'regexprep'))); assert(isempty(strfind(filetext, 'str2num'))); assert(isempty(strfind(filetext, 'if'))); assert(isempty(strfind(filetext, 'persistent'))); assert(isempty(strfind(filetext, 'global'))); assert(isempty(strfind(filetext, 'assignin'))); assert(isempty(strfind(filetext, 'evalin'))); assert(isempty(strfind(filetext, 'char'))); assert(isempty(strfind(filetext, 'interp1'))); assert(isempty(strfind(filetext, 'equal')));

3   Pass
m = 3; n = 4; y_correct = [ 1 1 1 1 1 2 1 1 3 1 1 4 1 2 2 1 2 3 1 2 4 1 3 3 1 3 4 1 4 4 2 2 2 2 2 3 2 2 4 2 3 3 2 3 4 2 4 4 3 3 3 3 3 4 3 4 4 4 4 4]; assert(isequal(putintoballs(m,n),y_correct))

i = 3 mn = 1 1 1 1 1 2 1 1 3 1 1 4 1 2 5 mn = 1 1 1 1 1 2 1 1 3 1 1 4 1 2 2 i = 3 mn = 1 1 1 1 1 2 1 1 3 1 1 4 1 2 2 1 2 3 1 2 4 1 3 5 mn = 1 1 1 1 1 2 1 1 3 1 1 4 1 2 2 1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