Cody

# Problem 44455. Find the average of a random sequance

Solution 1384612

Submitted on 18 Dec 2017 by shimon zusmanovsky
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))

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

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

n = 4 x = 0 y = 0 x = 1 y = 4 average = 4 n = 0

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

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

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

n = 0 x = 0 y = 0 average = 0

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

n = 8 x = 0 y = 0 x = 1 y = 8 average = 8 n = 9 x = 2 y = 17 average = 8.5000 n = 1 x = 3 y = 18 average = 6 n = 10 x = 4 y = 28 average = 7 n = 6 x = 5 y = 34 average = 6.8000 n = 1 x = 6 y = 35 average = 5.8333 n = 3 x = 7 y = 38 average = 5.4286 n = 6 x = 8 y = 44 average = 5.5000 n = 10 x = 9 y = 54 average = 6 n = 10 x = 10 y = 64 average = 6.4000 n = 1 x = 11 y = 65 average = 5.9091 n = 10 x = 12 y = 75 average = 6.2500 n = 10 x = 13 y = 85 average = 6.5385 n = 5 x = 14 y = 90 average = 6.4286 n = 8 x = 15 y = 98 average = 6.5333 n = 1 x = 16 y = 99 average = 6.1875 n = 4 x = 17 y = 103 average = 6.0588 n = 10 x = 18 y = 113 average = 6.2778 n = 8 x = 19 y = 121 average = 6.3684 n = 10 x = 20 y = 131 average = 6.5500 n = 7 x = 21 y = 138 average = 6.5714 n = 0