Cody

Problem 44359. 5th Time's a Charm

Solution 3680558

Submitted on 16 Nov 2020 by Brendan Nichols
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
x = 1; y1 = fifth_times_a_charm(x); assert(~isequal(y1,x)) y2 = fifth_times_a_charm(x); assert(~isequal(y2,x)) assert(abs(x-y2)<abs(x-y1)) y3 = fifth_times_a_charm(x); assert(~isequal(y3,x)) assert(abs(x-y3)<abs(x-y2)) y4 = fifth_times_a_charm(x); assert(~isequal(y4,x)) assert(abs(x-y4)<abs(x-y3)) y5 = fifth_times_a_charm(x); assert(isequal(y5,x))

n = 1 n = 2 n = 3 n = 4 n = 5

2   Pass
x = -1; y1 = fifth_times_a_charm(x); assert(~isequal(y1,x)) y2 = fifth_times_a_charm(x); assert(~isequal(y2,x)) assert(abs(x-y2)<abs(x-y1)) y3 = fifth_times_a_charm(x); assert(~isequal(y3,x)) assert(abs(x-y3)<abs(x-y2)) y4 = fifth_times_a_charm(x); assert(~isequal(y4,x)) assert(abs(x-y4)<abs(x-y3)) y5 = fifth_times_a_charm(x); assert(isequal(y5,x))

n = 1 n = 2 n = 3 n = 4 n = 5

3   Pass
x = 42; y1 = fifth_times_a_charm(x); assert(~isequal(y1,x)) y2 = fifth_times_a_charm(x); assert(~isequal(y2,x)) assert(abs(x-y2)<abs(x-y1)) y3 = fifth_times_a_charm(x); assert(~isequal(y3,x)) assert(abs(x-y3)<abs(x-y2)) y4 = fifth_times_a_charm(x); assert(~isequal(y4,x)) assert(abs(x-y4)<abs(x-y3)) y5 = fifth_times_a_charm(x); assert(isequal(y5,x))

n = 1 n = 2 n = 3 n = 4 n = 5

4   Pass
x = i; y1 = fifth_times_a_charm(x); assert(~isequal(y1,x)) y2 = fifth_times_a_charm(x); assert(~isequal(y2,x)) assert(abs(x-y2)<abs(x-y1)) y3 = fifth_times_a_charm(x); assert(~isequal(y3,x)) assert(abs(x-y3)<abs(x-y2)) y4 = fifth_times_a_charm(x); assert(~isequal(y4,x)) assert(abs(x-y4)<abs(x-y3)) y5 = fifth_times_a_charm(x); assert(isequal(y5,x))

n = 1 n = 2 n = 3 n = 4 n = 5

Community Treasure Hunt

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

Start Hunting!