Cody

Problem 661. Spot the outlier

Solution 2184520

Submitted on 31 Mar 2020 by Paul Morant
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
pts = [0 1; 0 2; 3 2; 0 3; 0 4 ]; outlier = 3; assert(isequal(spot_the_outlier(pts),outlier))

dydx = NaN -Inf 0.3333 -Inf -Inf Inf NaN 0 -Inf -Inf 0.3333 0 NaN -0.3333 -0.6667 Inf Inf -0.3333 NaN -Inf Inf Inf -0.6667 Inf NaN outlier = 3

2   Pass
pts = [10 -1;7 0;9.5 0.3;9 1.6;8.5 2.9]; outlier = 2; assert(isequal(spot_the_outlier(pts),outlier))

dydx = NaN -0.3333 -2.6000 -2.6000 -2.6000 -0.3333 NaN 0.1200 0.8000 1.9333 -2.6000 0.1200 NaN -2.6000 -2.6000 -2.6000 0.8000 -2.6000 NaN -2.6000 -2.6000 1.9333 -2.6000 -2.6000 NaN outlier = 2

3   Pass
pts = [-0.6 -6;-0.2 0;0 3;-0.8 -9;-2 1;-0.4 -3]; outlier = 5; assert(isequal(spot_the_outlier(pts),outlier))

dydx = NaN 15.0000 15.0000 15.0000 -5.0000 15.0000 15.0000 NaN 15.0000 15.0000 -0.5556 15.0000 15.0000 15.0000 NaN 15.0000 1.0000 15.0000 15.0000 15.0000 15.0000 NaN -8.3333 15.0000 -5.0000 -0.5556 1.0000 -8.3333 NaN -2.5000 15.0000 15.0000 15.0000 15.0000 -2.5000 NaN outlier = 5

4   Pass
pts = [2 5;0 4;0 0;4 6;-2 3]; outlier = 3; assert(isequal(spot_the_outlier(pts),outlier))

dydx = NaN 0.5000 2.5000 0.5000 0.5000 0.5000 NaN Inf 0.5000 0.5000 2.5000 -Inf NaN 1.5000 -1.5000 0.5000 0.5000 1.5000 NaN 0.5000 0.5000 0.5000 -1.5000 0.5000 NaN outlier = 3

5   Pass
pts = [1 0; 0 1; 1 2; 1.5 2.5; 2 3; 3 4 ]; outlier = 1; assert(isequal(spot_the_outlier(pts),outlier))

dydx = NaN -1 -Inf 5 3 2 -1 NaN 1 1 1 1 Inf 1 NaN 1 1 1 5 1 1 NaN 1 1 3 1 1 1 NaN 1 2 1 1 1 1 NaN outlier = 1

Community Treasure Hunt

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

Start Hunting!