Cody

Problem 44696. Sum of unique multiples of 3 and 5

Solution 3902183

Submitted on 29 Nov 2020
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   Fail
n = 15; sm_correct = 60; assert(isequal(sum3and5muls(n),sm_correct))

v = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 t = 1×15 logical array 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 f = 1×15 logical array 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 o = 0 0 1 0 1 1 0 0 1 1 0 1 0 0 2 o = 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1

Array indices must be positive integers or logical values. Error in sum3and5muls (line 9) sum_mult=sum(v(o)) Error in Test1 (line 3) assert(isequal(sum3and5muls(n),sm_correct))

2   Fail
n = 18; sm_correct = 78; assert(isequal(sum3and5muls(n),sm_correct))

v = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 t = 1×18 logical array 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 f = 1×18 logical array 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 o = 0 0 1 0 1 1 0 0 1 1 0 1 0 0 2 0 0 1 o = 0 0 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 1

Array indices must be positive integers or logical values. Error in sum3and5muls (line 9) sum_mult=sum(v(o)) Error in Test2 (line 3) assert(isequal(sum3and5muls(n),sm_correct))

3   Fail
n = (2^2)-1; sm_correct = 3; assert(isequal(sum3and5muls(n),sm_correct))

v = 1 2 3 t = 1×3 logical array 0 0 1 f = 1×3 logical array 0 0 0 o = 0 0 1 o = 0 0 1

Array indices must be positive integers or logical values. Error in sum3and5muls (line 9) sum_mult=sum(v(o)) Error in Test3 (line 3) assert(isequal(sum3and5muls(n),sm_correct))

4   Fail
n = randi(25); sm_correct = sum(3:3:n)+sum(5:5:n)-sum(15:15:n); assert(isequal(sum3and5muls(n),sm_correct))

v = 1 2 3 4 t = 1×4 logical array 0 0 1 0 f = 1×4 logical array 0 0 0 0 o = 0 0 1 0 o = 0 0 1 0

Array indices must be positive integers or logical values. Error in sum3and5muls (line 9) sum_mult=sum(v(o)) Error in Test4 (line 3) assert(isequal(sum3and5muls(n),sm_correct))

Suggested Problems

More from this Author29

Community Treasure Hunt

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

Start Hunting!