A city parks department is scouting locations for a new triangular flower bed. A surveyor drops three marker flags at integer grid coordinates on the site's coordinate map. The flower bed design is only valid if the three flags genuinely mark the corners of a triangle: no two flags may sit at the exact same spot, and the three flags must not all lie along one straight line. Given the three flag coordinates, determine whether they form a valid triangular placement.
A single line containing six space-separated integers x1 y1 x2 y2 x3 y3, the coordinates of the three flags.
Print true if the three points form a valid (non-degenerate) triangle, and false otherwise.
Example 1
Input
1 1 2 3 3 1
Expected
true
Explanation
The three points (1,1), (2,3), (3,1) are all distinct, and computing the cross product of the vectors from (1,1) to the other two points gives (2-1)*(1-1) - (3-1)*(3-1) = 0 - 4 = -4, which is nonzero, so the points are not collinear. They form a valid triangle, so the output is true.
Example 2
Input
1 1 2 2 3 3
Expected
false
Explanation
The three points (1,1), (2,2), (3,3) all lie on the line y = x. The cross product of the vectors from (1,1) to the other two points is (2-1)*(3-1) - (2-1)*(3-1) = 2 - 2 = 0, confirming collinearity, so the output is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →