Skip to content
playdsa
Preferences

Make yourself comfortable.

Saved on this browser. Your device’s reduced-motion preference is always respected.

Theme
Advanced settings

The Square Constellation

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Recognize four equal sides and two equal diagonals: The Square Constellation.

Brute force may pass the demo but fail when the world fills with players.

How you win

  1. 1Recognize when Valid square by distances matches the clues
  2. 2Keep this true after every move: the sorted six distances fully characterize the four-point square
  3. 3Reach the result within O(1) time and space

Rules and pressure

  • Target cost: O(1) time and space
  • State rule: the sorted six distances fully characterize the four-point square
Lesson 1 of 3

Live algorithm trace

Valid square by distances

Complete execution
1 of 5

Compute all six squared distances among four points.

1compute six squared pair distances
2sort the distances
3require smallest distance > 0
4require first four distances equal
5require final two distances equal
6require diagonal = 2 * side
pairDistances = 1,1,1,1,2,2
Truth to preserve / Cost target
Truth to preserve

the sorted six distances fully characterize the four-point square

Cost target

O(1) time and space

A square's six pairwise squared distances contain four equal positive sides and two equal diagonals, each twice a side. Squared distances avoid roots and orientation cases.

Your call · What should guide every step of this algorithm?

Help shape PlayDSA

Something confusing, broken, or missing? Leave a quick note without leaving your lesson.

Please leave out passwords, payment details and other private information.

Page included: /

Sign in to save feedback here, or send it with your email app. Your draft stays here while you sign in.

Open email instead