Cody

# Problem 194. Clockwise or Counterclockwise

Solution 1866295

Submitted on 5 Jul 2019 by John Simpson
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,-1,1,1]; y = [-1,1,1,-1]; d_correct = true; assert(isequal(isSortedClockwise(x,y),d_correct))

vx = 1 4 3 2 1 outer_x = -1 outer_y = -1 outer_x = -1 1 outer_y = -1 -1 outer_x = -1 1 1 outer_y = -1 -1 1 outer_x = -1 1 1 -1 outer_y = -1 -1 1 1 outer_x = -1 1 1 -1 -1 outer_y = -1 -1 1 1 -1 tf = logical 1

2   Pass
x = [-1,-1,-2,-2]; y = [-1,1,1,-1]; d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

vx = 1 2 3 4 1 outer_x = -1 outer_y = -1 outer_x = -1 -1 outer_y = -1 1 outer_x = -1 -1 -2 outer_y = -1 1 1 outer_x = -1 -1 -2 -2 outer_y = -1 1 1 -1 outer_x = -1 -1 -2 -2 -1 outer_y = -1 1 1 -1 -1 tf = logical 0

3   Pass
x = [-1,-1,-2,-2]; y = [-1,1,1,-1]; d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

vx = 1 2 3 4 1 outer_x = -1 outer_y = -1 outer_x = -1 -1 outer_y = -1 1 outer_x = -1 -1 -2 outer_y = -1 1 1 outer_x = -1 -1 -2 -2 outer_y = -1 1 1 -1 outer_x = -1 -1 -2 -2 -1 outer_y = -1 1 1 -1 -1 tf = logical 0

4   Pass
x = [-6,-7,-2,1,1,-2]; y = [4,-7,-13,-11,0,5]; d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

vx = 1 2 3 4 5 6 1 outer_x = -6 outer_y = 4 outer_x = -6 -7 outer_y = 4 -7 outer_x = -6 -7 -2 outer_y = 4 -7 -13 outer_x = -6 -7 -2 1 outer_y = 4 -7 -13 -11 outer_x = -6 -7 -2 1 1 outer_y = 4 -7 -13 -11 0 outer_x = -6 -7 -2 1 1 -2 outer_y = 4 -7 -13 -11 0 5 outer_x = -6 -7 -2 1 1 -2 -6 outer_y = 4 -7 -13 -11 0 5 4 tf = logical 0

5   Pass
x = [-59,-59,-55,-51,-50,-46,-45,-45,-39,-40,-40,-41,-46,-50,-50]; y = [-68,-33, -5,-13,-28,-30,-20,-10, -8,-23,-34,-45,-48,-51,-51]; d_correct = true; assert(isequal(isSortedClockwise(x,y),d_correct))

vx = 1 12 11 9 3 2 1 outer_x = -59 outer_y = -68 outer_x = -59 -41 outer_y = -68 -45 outer_x = -59 -41 -40 outer_y = -68 -45 -34 outer_x = -59 -41 -40 -39 outer_y = -68 -45 -34 -8 outer_x = -59 -41 -40 -39 -55 outer_y = -68 -45 -34 -8 -5 outer_x = -59 -41 -40 -39 -55 -59 outer_y = -68 -45 -34 -8 -5 -33 outer_x = -59 -41 -40 -39 -55 -59 -59 outer_y = -68 -45 -34 -8 -5 -33 -68 tf = logical 1

6   Pass
x = flip([-59,-59,-55,-51,-50,-46,-45,-45,-39,-40,-40,-41,-46,-50,-50]); y = flip([-68,-33, -5,-13,-28,-30,-20,-10, -8,-23,-34,-45,-48,-51,-51]); d_correct = false; assert(isequal(isSortedClockwise(x,y),d_correct))

vx = 4 5 7 13 14 15 4 outer_x = -41 outer_y = -45 outer_x = -41 -40 outer_y = -45 -34 outer_x = -41 -40 -39 outer_y = -45 -34 -8 outer_x = -41 -40 -39 -55 outer_y = -45 -34 -8 -5 outer_x = -41 -40 -39 -55 -59 outer_y = -45 -34 -8 -5 -33 outer_x = -41 -40 -39 -55 -59 -59 outer_y = -45 -34 -8 -5 -33 -68 outer_x = -41 -40 -39 -55 -59 -59 -41 outer_y = -45 -34 -8 -5 -33 -68 -45 tf = logical 0

7   Pass
x = [1,1,2,2]; y = [2,1,1,2]; assert(isequal(isSortedClockwise(x,y),false));

vx = 1 2 3 4 1 outer_x = 1 outer_y = 2 outer_x = 1 1 outer_y = 2 1 outer_x = 1 1 2 outer_y = 2 1 1 outer_x = 1 1 2 2 outer_y = 2 1 1 2 outer_x = 1 1 2 2 1 outer_y = 2 1 1 2 2 tf = logical 0

8   Pass
x = flip([1,1,2,2]); y = flip([2,1,1,2]); assert(isequal(isSortedClockwise(x,y),true));

vx = 1 4 3 2 1 outer_x = 2 outer_y = 2 outer_x = 2 1 outer_y = 2 2 outer_x = 2 1 1 outer_y = 2 2 1 outer_x = 2 1 1 2 outer_y = 2 2 1 1 outer_x = 2 1 1 2 2 outer_y = 2 2 1 1 2 tf = logical 1

9   Pass
x = [-2,-2,-4,-4]; y = [1,3,1,-1]; assert(isequal(isSortedClockwise(x,y),false));

vx = 1 2 3 4 1 outer_x = -2 outer_y = 1 outer_x = -2 -2 outer_y = 1 3 outer_x = -2 -2 -4 outer_y = 1 3 1 outer_x = -2 -2 -4 -4 outer_y = 1 3 1 -1 outer_x = -2 -2 -4 -4 -2 outer_y = 1 3 1 -1 1 tf = logical 0

10   Pass
x = flip([-2,-2,-4,-4]); y = flip([1,3,1,-1]); assert(isequal(isSortedClockwise(x,y),true));

vx = 1 4 3 2 1 outer_x = -4 outer_y = -1 outer_x = -4 -2 outer_y = -1 1 outer_x = -4 -2 -2 outer_y = -1 1 3 outer_x = -4 -2 -2 -4 outer_y = -1 1 3 1 outer_x = -4 -2 -2 -4 -4 outer_y = -1 1 3 1 -1 tf = logical 1

11   Pass
r=rand(100,15); a=2*pi*rand(100,1); d=2*(rand(100,1)>.5)-1; x=r.*cos(a*ones(1,15)+d*2*pi*(0:14)/15)+randn(100,1); y=r.*sin(a*ones(1,15)+d*2*pi*(0:14)/15)+randn(100,1); assert(all(arrayfun(@(i)isequal(isSortedClockwise(x(i,:),y(i,:)),d(i)<0),1:100)))

vx = 2 3 6 10 11 13 15 2 outer_x = 0.7126 outer_y = 1.1988 outer_x = 0.7126 0.4895 outer_y = 1.1988 0.9009 outer_x = 0.7126 0.4895 0.7062 outer_y = 1.1988 0.9009 0.0933 outer_x = 0.7126 0.4895 0.7062 1.6892 outer_y = 1.1988 0.9009 0.0933 -0.2481 outer_x = 0.7126 0.4895 0.7062 1.6892 1.9589 outer_y = 1.1988 0.9009 0.0933 -0.2481 0.0013 outer_x = 0.7126 0.4895 0.7062 1.6892 1.9589 1.6245 outer_y = 1.1988 0.9009 0.0933 -0.2481 0.0013 0.5890 outer_x = 0.7126 0.4895 0.7062 1.6892 1.9589 1.6245 1.3670 outer_y = 1.1988 0.9009 0.0933 -0.2481 0.0013 0.5890 1.0092 outer_x = 0.7126 0.4895 0.7062 1.6892 1.9589 1.6245 1.3670 0.7126 outer_y = 1.1988 0.9009 0.0933 -0.2481 0.0013 0.5890 1.0092 1.1988 tf = logical 0 vx = 1 2 4 5 6 9 13 1 outer_x = -0.7382 outer_y = -0.3169 outer_x = -0.7382 -0.3539 outer_y = -0.3169 -0.1950 outer_x = -0.7382 -0.3539 -0.2219 outer_y = -0.3169 -0.1950 0.5460 outer_x = -0.7382 -0.3539 -0.2219 -0.2390 outer_y = -0.3169 -0.1950 0.5460 0.9083 outer_x = -0.7382 -0.3539 -0.2219 -0.2390 -0.4370 outer_y = -0.3169 -0.1950 0.5460 0.9083 1.2363 outer_x = -0.7382 -0.3539 -0.2219 -0.2390 -0.4370 -1.5218 outer_y = -0.3169 -0.1950 0.5460 0.9083 1.2363 1.2902 outer_x = -0.7382 -0.3539 -0.2219 -0.2390 -0.4370 -1.5218 -1.6584 outer_y = -0.3169 -0.1950 0.5460 0.9083 1.2363 1.2902 0.0374 outer_x = -0.7382 -0.3539 -0.2219 -0.2390 -0.4370 -1.5218 -1.6584 -0.7382 outer_y = -0.3169 -0.1950 0.5460 0.9083 1.2363 1.2902 0.0374 -0.3169 tf = logical 0 vx = 5 15 13 12 11 8 5 outer_x = 1.3487 outer_y = -0.1747 outer_x = 1.3487 0.6247 outer_y = -0.1747 -0.2180 outer_x = 1.3487 0.6247 -0.0357 outer_y = -0.1747 -0.2180 -0.4605 outer_x = 1.3487 0.6247 -0.0357 0.1282 outer_y = -0.1747 -0.2180 -0.4605 -0.7566 outer_x = 1.3487 0.6247 -0.0357 0.1282 0.4488 outer_y = -0.1747 -0.2180 -0.4605 -0.7566 -0.8459 outer_x = 1.3487 0.6247 -0.0357 0.1282 0.4488 1.0744 outer_y = -0.1747 -0.2180 -0.4605 -0.7566 -0.8459 -0.7448 outer_x = 1.3487 0.6247 -0.0357 0.1282 0.4488 1.0744 1.3487 outer_y = -0.1747 -0.2180 -0.4605 -0.7566 -0.8459 -0.7448 -0.1747 tf = logical 1 vx = 3 4 6 9 12 14 15 3 outer_x = -0.6049 outer_y = -0.5850 outer_x = -0.6049 -0.4631 outer_y = -0.5850 -0.8107 outer_x = -0.6049 -0.4631 0.0591 outer_y = -0.5850 -0.8107 -1.1145 outer_x = -0.6049 -0.4631 0.0591 0.8633 outer_y = -0.5850 -0.8107 -1.1145 -0.5007 outer_x = -0.6049 -0.4631 0.0591 0.8633 0.2692 outer_y = -0.5850 -0.8107 -1.1145 -0.5007 0.2205 outer_x = -0.6049 -0.4631 0.0591 0.8633 0.2692 -0.3313 outer_y = -0.5850 -0.8107 -1.1145 -0.5007 0.2205 0.5516 outer_x = -0.6049 -0.4631 0.0591 0.8633 0.2692 -0.3313 -0.5581 outer_y = -0.5850 -0.8107 -1.1145 -0.5007 0.2205 0.5516 0.2441 outer_x = -0.6049 -0.4631 0.0591 0.8633 0.2692 -0.3313 -0.5581 -0.6049 outer_y = -0.5850 -0.8107 -1.1145 -0.5007 0.2205 0.5516 0.2441 -0.5850 tf = logical 0 vx = 2 15 12 10 7 5 2 outer_x = -1.5765 outer_y = -1.6770 outer_x = -1.5765 -1.9390 outer_y = -1.6770 -1.9911 outer_x = -1.5765 -1.9390 -1.7897 outer_y = -1.6770 -1.9911 -2.6561 outer_x = -1.5765 -1.9390 -1.7897 -1.3147 outer_y = -1.6770 -1.9911 -2.6561 -3.2234 outer_x = -1.5765 -1.9390 -1.7897 -1.3147 -0.9494 outer_y = -1.6770 -1.9911 -2.6561 -3.2234 -2.3432 outer_x = -1.5765 -1.9390 -1.7897 -1.3147 -0.9494 -0.8165 outer_y = -1.6770 -1.9911 -2.6561 -3.2234 -2.3432 -1.8268 outer_x = -1.5765 -1.9390 -1.7897 -1.3147 -0.9494 -0.8165 -1.5765 outer_y = -1.6770 -1.9911 -2.6561 -3.2234 -2.3432 -1.8268 -1.6770 tf = logical 1 vx = 2 15 10 7 4 2 outer_x = 1.4756 outer_y = -1.1045 outer_x = 1.4756 1.4430 outer_y = -1.1045 -0.4916 outer_x = 1.4756 1.4430 0.6643 outer_y = -1.1045 -0.4916 0.1915 outer_x = 1.4756 1.4430 0.6643 0.1168 outer_y = -1.1045 -0.4916 0.1915 -0.5714 outer_x = 1.4756 1.4430 0.6643 0.1168 0.8618 outer_y = -1.1045 -0.4916 0.1915 -0.5714 -1.0777 outer_x = 1.4756 1.4430 0.6643 0.1168 0.8618 1.4756 outer_y = -1.1045 -0.4916 0.1915 -0.5714 -1.0777 -1.1045 tf = logical 1 vx = 2 14 11 8 5 2 outer_x = -2.3924 outer_y = 1.7467 outer_x = -2.3924 -2.1155 outer_y = 1.7467 0.8408 outer_x = -2.3924 -2.1155 -1.2548 outer_y = 1.7467 0.8408 1.4768 outer_x = -2.3924 -2.1155 -1.2548 -1.7565 outer_y = 1.7467 0.8408 1.4768 2.0740 outer_x = -2.3924 -2.1155 -1.2548 -1.7565 -2.4317 outer_y = 1.7467 0.8408 1.4768 2.0740 2.6226 outer_x = -2.3924 -2.1155 -1.2548 -1.7565 -2.4317 -2.3924 outer_y = 1.7467 0.8408 1.4768 2.0740 2.6226 1.7467 tf = logical 1 vx = 1 15 14 13 11 8 6 5 4 1 outer_x = -0.9874 outer_y = 1.2179 outer_x = -0.9874 -1.2403 outer_y = 1.2179 0.9964 outer_x = -0.9874 -1.2403 -1.4028 outer_y = 1.2179 0.9964 0.7508 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 outer_y = 1.2179 0.9964 0.7508 0.4887 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 -1.4497 outer_y = 1.2179 0.9964 0.7508 0.4887 -0.1627 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 -1.4497 -0.5847 outer_y = 1.2179 0.9964 0.7508 0.4887 -0.1627 -0.0976 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 -1.4497 -0.5847 0.1288 outer_y = 1.2179 0.9964 0.7508 0.4887 -0.1627 -0.0976 0.1099 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 -1.4497 -0.5847 0.1288 0.1514 outer_y = 1.2179 0.9964 0.7508 0.4887 -0.1627 -0.0976 0.1099 0.5174 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 -1.4497 -0.5847 0.1288 0.1514 -0.0079 outer_y = 1.2179 0.9964 0.7508 0.4887 -0.1627 -0.0976 0.1099 0.5174 0.8816 outer_x = -0.9874 -1.2403 -1.4028 -1.5535 -1.4497 -0.5847 0.1288 0.1514 -0.0079 -0.9874 outer_y = 1.2179 0.9964 0.7508 0.4887 -0.1627 -0.0976 0.1099 0.5174 0.8816 1.2179 tf = logical 1 vx = 2 14 12 8 4 2 outer_x = 1.8993 outer_y = -1.2894 outer_x = 1.8993 2.6703 outer_y = -1.2894 -0.5880 outer_x = 1.8993 2.6703 2.3629 outer_y = -1.2894 -0.5880 -0.0247 outer_x = 1.8993 2.6703 2.3629 1.2007 outer_y = -1.2894 -0.5880 -0.0247 0.3787 outer_x = 1.8993 2.6703 2.3629 1.2007 1.2565 outer_y = -1.2894 -0.5880 -0.0247 0.3787 -0.9791 outer_x = 1.8993 2.6703 2.3629 1.2007 1.2565 1.8993 outer_y = -1.2894 -0.5880 -0.0247 0.3787 -0.9791 -1.2894 tf = logical 1 vx = 4 5 8 10 11 13 15 4 outer_x = -2.2588 outer_y = 0.2915 outer_x = -2.2588 -2.0671 outer_y = 0.2915 -0.0628 outer_x = -2.2588 -2.0671 -1.3257 outer_y = 0.2915 -0.0628 -0.5374 outer_x = -2.2588 -2.0671 -1.3257 -0.8393 outer_y = 0.2915 -0.0628 -0.5374 -0.2899 outer_x = -2.2588 -2.0671 -1.3257 -0.8393 -0.5677 outer_y = 0.2915 -0.0628 -0.5374 -0.2899 -0.1108 outer_x = -2.2588 -2.0671 -1.3257 -0.8393 -0.5677 -0.7793 outer_y = 0.2915 -0.0628 -0.5374 -0.2899 -0.1108 0.4338 outer_x = -2.2588 -2.0671 -1.3257 -0.8393 -0.5677 -0.7793 -1.1059 outer_y = 0.2915 -0.0628 -0.5374 -0.2899 -0.1108 0.4338 0.9389 outer_x = -2.2588 -2.0671 -1.3257 -0.8393 -0.5677 -0.7793 -1.1059 -2.2588 outer_y = 0.2915 -0.0628 -0.5374 -0.2899 -0.1108 0.4338 0.9389 0.2915 tf = logical 0 vx = 2 15 12 9 8 5 2 outer_x = -0.1530 outer_y = -0.6187 outer_x = -0.1530 0.3098 outer_y = -0.6187 -0.9359 outer_x = -0.1530 0.3098 1.2995 outer_y = -0.6187 -0.9359 -0.6767 outer_x = -0.1530 0.3098 1.2995 1.0396 outer_y = -0.6187 -0.9359 -0.6767 0.4118 outer_x = -0.1530 0.3098 1.2995 1.0396 0.7093 outer_y = -0.6187 -0.9359 -0.6767 0.4118 0.5844 outer_x = -0.1530 0.3098 1.2995 1.0396 0.7093 -0.2577 outer_y = -0.6187 -0.9359 -0.6767 0.4118 0.5844 0.2801 outer_x = -0.1530 0.3098 1.2995 1.0396 0.7093 -0.2577 -0.1530 o...

### Community Treasure Hunt

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

Start Hunting!