Cody

# Problem 44455. Find the average of a random sequance

Solution 1447048

Submitted on 22 Feb 2018 by Yair Fridman
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))

s = 0 n = 0 v = 4 n = 1 s = 4 v = 7 average = 4 n = 2 s = 11 v = 0 average = 5.5000

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

s = 0 n = 0 v = 4 n = 1 s = 4 v = 0 average = 4

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

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

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

s = 0 n = 0 v = 0 average = 0

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

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

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!