Cody

Problem 51. Find the two most distant points

Solution 1874433

Submitted on 15 Jul 2019 by Rory Hughes
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
p = [0 0; 1 0; 2 2; 0 1]; ix_correct = [1 3]; assert(isequal(mostDistant(p),ix_correct))

max_dist = 0 best_i = 0 best_j = 0 dist = 0 dist = 1 max_dist = 1 best_i = 2 best_j = 1 dist = 2.8284 max_dist = 2.8284 best_i = 3 best_j = 1 dist = 1 dist = 1 dist = 0 dist = 2.2361 dist = 1.4142 dist = 2.8284 dist = 2.2361 dist = 0 dist = 2.2361 dist = 1 dist = 1.4142 dist = 2.2361 dist = 0 ix = 1 3

2   Pass
p = [0 0; 1 0; 2 2; 0 10]; ix_correct = [2 4]; assert(isequal(mostDistant(p),ix_correct))

max_dist = 0 best_i = 0 best_j = 0 dist = 0 dist = 1 max_dist = 1 best_i = 2 best_j = 1 dist = 2.8284 max_dist = 2.8284 best_i = 3 best_j = 1 dist = 10 max_dist = 10 best_i = 4 best_j = 1 dist = 1 dist = 0 dist = 2.2361 dist = 10.0499 max_dist = 10.0499 best_i = 4 best_j = 2 dist = 2.8284 dist = 2.2361 dist = 0 dist = 8.2462 dist = 10 dist = 10.0499 dist = 8.2462 dist = 0 ix = 2 4

3   Pass
p = [0 0; -1 50]; ix_correct = [1 2]; assert(isequal(mostDistant(p),ix_correct))

max_dist = 0 best_i = 0 best_j = 0 dist = 0 dist = 50.0100 max_dist = 50.0100 best_i = 2 best_j = 1 dist = 50.0100 dist = 0 ix = 1 2

4   Pass
p = [5 5; 1 0; 2 2; 0 10; -100 20; 1000 400]; ix_correct = [5 6]; assert(isequal(mostDistant(p),ix_correct))

max_dist = 0 best_i = 0 best_j = 0 dist = 0 dist = 6.4031 max_dist = 6.4031 best_i = 2 best_j = 1 dist = 4.2426 dist = 7.0711 max_dist = 7.0711 best_i = 4 best_j = 1 dist = 106.0660 max_dist = 106.0660 best_i = 5 best_j = 1 dist = 1.0705e+03 max_dist = 1.0705e+03 best_i = 6 best_j = 1 dist = 6.4031 dist = 0 dist = 2.2361 dist = 10.0499 dist = 102.9612 dist = 1.0761e+03 max_dist = 1.0761e+03 best_i = 6 best_j = 2 dist = 4.2426 dist = 2.2361 dist = 0 dist = 8.2462 dist = 103.5761 dist = 1.0744e+03 dist = 7.0711 dist = 10.0499 dist = 8.2462 dist = 0 dist = 100.4988 dist = 1.0734e+03 dist = 106.0660 dist = 102.9612 dist = 103.5761 dist = 100.4988 dist = 0 dist = 1.1638e+03 max_dist = 1.1638e+03 best_i = 6 best_j = 5 dist = 1.0705e+03 dist = 1.0761e+03 dist = 1.0744e+03 dist = 1.0734e+03 dist = 1.1638e+03 dist = 0 ix = 5 6

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!