added more samples to the test
Hello, Alfonso Nieto-Castanon. This is a very nice problem. It was interesting to see the variety of approaches used to solve it. It was also interesting to notice a few submissions failed your added test cases from circa Dec 2017. Do you allow for self-intersecting polygons, as per https://en.wikipedia.org/wiki/Polygon ?
I suspect a common solution tactic will fail badly when faced with self-intersecting polygons. —DIV
...On second thought, maybe there's no consistent definition of CW/CCW for self-intersecting polygons, such as figure-eight or bow-tie ("cross-quadrilateral") shapes.
the last test
I don't understand why the vector sizes of x and y for the last test case are both 100x15. The problem strictly says that the points are 2-dimensional. Can someone explain this?
I like the readability of this submission. However the logic of the if statement is curious to me: it seems that after setting tf to false, tf can be reset back to true. Would it be more robust to either (i) initialise tf before your loop, or (ii) include a "break" command?
Simply beautiful!
Didn't realize ispolycw was in the Mapping Toolbox, and not Cody friendly.
This method (as well as several others) would fail in a more extensive test suite; for example, when x = [1,1,2] and y = [2,1,1]; or when x = [-2,-2,-4,-4] and y = [1,3,1,-1]; or when x = [-1,-1,3] and y = [-3,1,1].
@yurenchu, Thanks for pointing this out, I have added a few more test cases now
Remove all the words that end with "ain"
1304 Solvers
4543 Solvers
Test if two numbers have the same digits
189 Solvers
379 Solvers
224 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!