Cody

# Problem 229. Fizz Buzz

Solution 87156

Submitted on 9 May 2012 by Aurelien Queffurust
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
%% x = 1; y_correct = {'1'}; assert(isequal(fizzbuzz(x),y_correct))

C = '1' locfizzbuzz = [] C = '1' locbuzz = [] C = '1' locfizz = [] C = '1'

2   Pass
%% x = 3; y_correct = {'fizz'}; assert(isequal(fizzbuzz(x),y_correct))

C = '3' locfizzbuzz = [] C = '3' locbuzz = [] C = '3' locfizz = 1 C = 'fizz'

3   Pass
%% x = 5; y_correct = {'buzz'}; assert(isequal(fizzbuzz(x),y_correct))

C = '5' locfizzbuzz = [] C = '5' locbuzz = 1 C = 'buzz' locfizz = [] C = 'buzz'

4   Pass
%% x = 15; y_correct = {'fizzbuzz'}; assert(isequal(fizzbuzz(x),y_correct))

C = '15' locfizzbuzz = 1 C = 'fizzbuzz' locbuzz = [] C = 'fizzbuzz' locfizz = [] C = 'fizzbuzz'

5   Pass
%% x = [1 3 5 15 16]; y_correct = {'1', 'fizz', 'buzz', 'fizzbuzz','16'}; assert(isequal(fizzbuzz(x),y_correct))

C = '1' '3' '5' '15' '16' locfizzbuzz = 4 C = '1' '3' '5' 'fizzbuzz' '16' locbuzz = 3 C = '1' '3' 'buzz' 'fizzbuzz' '16' locfizz = 2 C = '1' 'fizz' 'buzz' 'fizzbuzz' '16'

6   Pass
%% x = []; y_correct = {}; assert(isequal(fizzbuzz(x),y_correct))

C = {} locfizzbuzz = [] C = {} locbuzz = [] C = {} locfizz = [] C = {}

7   Pass
%% x = 1:100; y_correct = arrayfun(@(n)num2str(n), x, 'uniform', false); y_correct(mod(x, 3)==0) = {'fizz'}; y_correct(mod(x, 5)==0) = {'buzz'} y_correct(mod(x, 15)==0) = {'fizzbuzz'}; assert(isequal(fizzbuzz(x),y_correct))

y_correct = Columns 1 through 7 '1' '2' 'fizz' '4' 'buzz' 'fizz' '7' Columns 8 through 14 '8' 'fizz' 'buzz' '11' 'fizz' '13' '14' Columns 15 through 20 'buzz' '16' '17' 'fizz' '19' 'buzz' Columns 21 through 26 'fizz' '22' '23' 'fizz' 'buzz' '26' Columns 27 through 32 'fizz' '28' '29' 'buzz' '31' '32' Columns 33 through 38 'fizz' '34' 'buzz' 'fizz' '37' '38' Columns 39 through 44 'fizz' 'buzz' '41' 'fizz' '43' '44' Columns 45 through 50 'buzz' '46' '47' 'fizz' '49' 'buzz' Columns 51 through 56 'fizz' '52' '53' 'fizz' 'buzz' '56' Columns 57 through 62 'fizz' '58' '59' 'buzz' '61' '62' Columns 63 through 68 'fizz' '64' 'buzz' 'fizz' '67' '68' Columns 69 through 74 'fizz' 'buzz' '71' 'fizz' '73' '74' Columns 75 through 80 'buzz' '76' '77' 'fizz' '79' 'buzz' Columns 81 through 86 'fizz' '82' '83' 'fizz' 'buzz' '86' Columns 87 through 92 'fizz' '88' '89' 'buzz' '91' '92' Columns 93 through 98 'fizz' '94' 'buzz' 'fizz' '97' '98' Columns 99 through 100 'fizz' 'buzz' C = Columns 1 through 8 '1' '2' '3' '4' '5' '6' '7' '8' Columns 9 through 15 '9' '10' '11' '12' '13' '14' '15' Columns 16 through 22 '16' '17' '18' '19' '20' '21' '22' Columns 23 through 29 '23' '24' '25' '26' '27' '28' '29' Columns 30 through 36 '30' '31' '32' '33' '34' '35' '36' Columns 37 through 43 '37' '38' '39' '40' '41' '42' '43' Columns 44 through 50 '44' '45' '46' '47' '48' '49' '50' Columns 51 through 57 '51' '52' '53' '54' '55' '56' '57' Columns 58 through 64 '58' '59' '60' '61' '62' '63' '64' Columns 65 through 71 '65' '66' '67' '68' '69' '70' '71' Columns 72 through 78 '72' '73' '74' '75' '76' '77' '78' Columns 79 through 85 '79' '80' '81' '82' '83' '84' '85' Columns 86 through 92 '86' '87' '88' '89' '90' '91' '92' Columns 93 through 99 '93' '94' '95' '96' '97' '98' '99' Column 100 '100' locfizzbuzz = 15 30 45 60 75 90 C = Columns 1 through 8 '1' '2' '3' '4' '5' '6' '7' '8' Columns 9 through 15 '9' '10' '11' '12' '13' '14' 'fizzbuzz' Columns 16 through 22 '16' '17' '18' '19' '20' '21' '22' Columns 23 through 29 '23' '24' '25' '26' '27' '28' '29' Columns 30 through 35 'fizzbuzz' '31' '32' '33' '34' '35' Columns 36 through 42 '36' '37' '38' '39' '40' '41' '42' Columns 43 through 48 '43' '44' 'fizzbuzz' '46' '47' '48' Columns 49 through 55 '49' '50' '51' '52' '53' '54' '55' Columns 56 through 61 '56' '57' '58' '59' 'fizzbuzz' '61' Columns 62 through 68 '62' '63' '64' '65' '66' '67' '68' Columns 69 through 74 '69' '70' '71' '72' '73' '74' Columns 75 through 80 'fizzbuzz' '76' '77' '78' '79' '80' Columns 81 through 87 '81' '82' '83' '84' '85' '86' '87' Columns 88 through 93 '88' '89' 'fizzbuzz' '91' '92' '93' Columns 94 through 100 '94' '95' '96' '97' '98' '99' '100' locbuzz = Columns 1 through 10 5 10 20 25 35 40 50 55 65 70 Columns 11 through 14 80 85 95 100 C = Columns 1 through 8 '1' '2' '3' '4' 'buzz' '6' '7' '8' Columns 9 through 14 '9' 'buzz' '11' '12' '13' '14' Columns 15 through 20 'fizzbuzz' '16' '17' '18' '19' 'buzz' Columns 21 through 27 '21' '22' '23' '24' 'buzz' '26' '27' Columns 28 through 33 '28' '29' 'fizzbuzz' '31' '32' '33' Columns 34 through 40 '34' 'buzz' '36' '37' '38' '39' 'buzz' Columns 41 through 46 '41' '42' '43' '44' 'fizzbuzz' '46' Columns 47 through 53 '47' '48' '49' 'buzz' '51' '52' '53' Columns 54 through 59 '54' 'buzz' '56' '57' '58' '59' Columns 60 through 65 'fizzbuzz' '61' '62' '63' '64' 'buzz' Columns 66 through 72 '66' '67' '68' '69' 'buzz' '71' '72' Columns 73 through 78 '73' '74' 'fizzbuzz' '76' '77' '78' Columns 79 through 85 '79' 'buzz' '81' '82' '83' '84' 'buzz' Columns 86 through 91 '86' '87' '88' '89' 'fizzbuzz' '91' Columns 92 through 98 '92' '93' '94' 'buzz' '96' '97' '98' Columns 99 through 100 '99' 'buzz' locfizz = Columns 1 through 10 3 6 9 12 18 21 24 27 33 36 Columns 11 through 20 39 42 48 51 54 57 63 66 69 72 Columns 21 through 27 78 81 84 87 93 96 99 C = Columns 1 through 7 '1' '2' 'fizz' '4' 'buzz' 'fizz' '7' Columns 8 through 14 '8' 'fizz' 'buzz' '11' 'fizz' '13' '14' Columns 15 through 20 'fizzbuzz' '16' '17' 'fizz' '19' 'buzz' Columns 21 through 26 'fizz' '22' '23' 'fizz' 'buzz' '26' Columns 27 through 32 'fizz' '28' '29' 'fizzbuzz' '31' '32' Columns 33 through 38 'fizz' '34' 'buzz' 'fizz' '37' '38' Columns 39 through 44 'fizz' 'buzz' '41' 'fizz' '43' '44' Columns 45 through 50 'fizzbuzz' '46' '47' 'fizz' '49' 'buzz' Columns 51 through 56 'fizz' '52' '53' 'fizz' 'buzz' '56' Columns 57 through 62 'fizz' '58' '59' 'fizzbuzz' '61' '62' Columns 63 through 68 'fizz' '64' 'buzz' 'fizz' '67' '68' Columns 69 through 74 'fizz' 'buzz' '71' 'fizz' '73' '74' Columns 75 through 80 'fizzbuzz' '76' '77' 'fizz' '79' 'buzz' Columns 81 through 86 'fizz' '82' '83' 'fizz' 'buzz' '86' Columns 87 through 92 'fizz' '88' '89' 'fizzbuzz' '91' '92' Columns 93 through 98 'fizz' '94' 'buzz' 'fizz' '97' '98' Columns 99 through 100 'fizz' 'buzz'