Cody

Problem 44779. Don't be mean. Be nice!

Solution 2730543

Submitted on 23 Jul 2020 by Dennis Gimlin
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
R=1:4;k=2;y_correct = 27.5; a=dont_be_mean(R,k) assert(abs(a-y_correct)<1e-10)

y = 27.5000 a = 27.5000

2   Pass
R=0:8;k=3;y_correct = 493.3125; a=dont_be_mean(R,k) assert(abs(a-y_correct)<1e-10)

y = 493.3125 a = 493.3125

3   Pass
R=[1 2 4 6 8];k=4;y_correct = 4666.2; a=dont_be_mean(R,k) assert(abs(a-y_correct)<1e-10)

y = 4.6662e+03 a = 4.6662e+03

4   Pass
R=[2 8 6 7 4 5];k=1;y_correct = 5.33333333333333; a=dont_be_mean(R,k) assert(abs(a-y_correct)<1e-10)

y = 5.3333 a = 5.3333

5   Pass
R=0:9; y=0; for k=1:8 y=y+dont_be_mean(R,k); end y_correct=61042519.44444444; assert(abs(y-y_correct)<1e-3)

y = 5 y = 54.4444 y = 548.8889 y = 5.4933e+03 y = 5.4938e+04 y = 5.4938e+05 y = 5.4938e+06 y = 5.4938e+07

Community Treasure Hunt

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

Start Hunting!