Cody

Solution 419600

Submitted on 18 Mar 2014 by Tim
  • Size: 51
  • This is the leading solution.
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
%% F = [0 0 1 1;0 1 1 0]; a = 1; b = 3; d = polygon_distance(F,a,b); d_correct = 2; assert(isequal(d,d_correct))
2   Pass
%% F = [0 0 1 1;0 1 1 0]; a = 1; b = 2; d = polygon_distance(F,a,b); d_correct = 1; assert(isequal(d,d_correct))
3   Pass
%% F = [0 0 1 1;0 1 1 0]; a = 4; b = 1; d = polygon_distance(F,a,b); d_correct = 1; assert(isequal(d,d_correct))
4   Pass
%% F = [0 0 1 1;0 1 1 0]; a = 3; b = 3; d = polygon_distance(F,a,b); d_correct = 0; assert(isequal(d,d_correct))
5   Pass
%% F = [zeros(1,101) ones(1,101);0:100 100:-1:0]; a = 1; for b = randi(size(F,2)/2,1,100) d = polygon_distance(F,a,b); d_correct = b-1; assert(isequal(d,d_correct)); end
6   Pass
%% F = [zeros(1,101) ones(1,101);0:100 100:-1:0]; a = 1; for b = randi(size(F,2)/2,1,100)+size(F,2)/2 s = rand(1)+1; d = polygon_distance(F*s,a,b); d_correct = (size(F,2)-b+1)*s; assert(abs(d-d_correct)<1e-10); end