Math Fundamentals18 sections · 814 units
Open in Course

Valid Square - Algorithm

(Distance set approach)

1.1. Compute all 6 pairwise distances: d(p1,p2), d(p1,p3), d(p1,p4), d(p2,p3), d(p2,p4), d(p3,p4) 2.2. Store distances in a set to find unique values 3.3. If any distance is 0, return false (duplicate points) 4.4. If there are exactly 2 unique distances, check counts: - Smaller distance appears 4 times (sides) - Larger distance appears 2 times (diagonals) 5.5. If both conditions hold, return true 6.6. Otherwise, return false