Cody

# Problem 44455. Find the average of a random sequance

Solution 1538158

Submitted on 23 May 2018 by elroie winderbouim ben ami
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
filetext = fileread('MeanWhile.m'); assert(isempty(strfind(filetext, 'regexp')),'regexp hacks are forbidden')

2   Pass
filetext = fileread('MeanWhile.m'); assert(isempty(strfind(filetext, 'sum')),'sum() function is forbidden')

3   Pass
filetext = fileread('MeanWhile.m'); assert(isempty(strfind(filetext, 'mean')),'mean() function is forbidden')

4   Pass
rng(1); av_correct = 5.5; assert(isequal(MeanWhile(),av_correct))

i = 0 n = 0 x = 1 x = 4 n = 4 i = 1 x = 7 n = 11 i = 2 x = 0 n = 11 average = 5.5000

5   Pass
rng(2); av_correct = 4; assert(isequal(MeanWhile(),av_correct))

i = 0 n = 0 x = 1 x = 4 n = 4 i = 1 x = 0 n = 4 average = 4

6   Pass
rng(3); av_correct = 5.25; assert(isequal(MeanWhile(),av_correct))

i = 0 n = 0 x = 1 x = 6 n = 6 i = 1 x = 7 n = 13 i = 2 x = 3 n = 16 i = 3 x = 5 n = 21 i = 4 x = 9 n = 30 i = 5 x = 9 n = 39 i = 6 x = 1 n = 40 i = 7 x = 2 n = 42 i = 8 x = 0 n = 42 average = 5.2500

7   Pass
rng(7); av_correct = 0; assert(isequal(MeanWhile(),av_correct))

i = 0 n = 0 x = 1 x = 0 n = 0 i = 1 average = 0

8   Pass
rng(0); av_correct = 6.571428571428571; assert(isequal(MeanWhile(),av_correct))

i = 0 n = 0 x = 1 x = 8 n = 8 i = 1 x = 9 n = 17 i = 2 x = 1 n = 18 i = 3 x = 10 n = 28 i = 4 x = 6 n = 34 i = 5 x = 1 n = 35 i = 6 x = 3 n = 38 i = 7 x = 6 n = 44 i = 8 x = 10 n = 54 i = 9 x = 10 n = 64 i = 10 x = 1 n = 65 i = 11 x = 10 n = 75 i = 12 x = 10 n = 85 i = 13 x = 5 n = 90 i = 14 x = 8 n = 98 i = 15 x = 1 n = 99 i = 16 x = 4 n = 103 i = 17 x = 10 n = 113 i = 18 x = 8 n = 121 i = 19 x = 10 n = 131 i = 20 x = 7 n = 138 i = 21 x = 0 n = 138 average = 6.5714