← Back to challenges

Four Points Make a Square

PythonHardalgorithmsconditionsgeometrymathvalidation

Instructions

The function is given four points with (x, y) coordinates in no particular order. Determine if these points make a square and return True / False.

A square has four equal sides with positive length and four 90-degree angles.

Examples

valid_square((0, 0), (1, 1), (1, 0), (0, 1)) ➞ True

valid_square((0, 0), (1, 1), (1, 0), (0, 12)) ➞ False

valid_square((1, 0), (-1, 0), (0, 1), (0, -1)) ➞ True

valid_square((0, 0), (0, 0), (0, 0), (0, 0)) ➞ False

Notes

A square also has equal diagonals.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.