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 Collinear Stars

Learn
Play
Prove
Problem context and objectives
Mission briefing

Puzzle systems engineer · A game mechanic is behaving incorrectly

Normalize every direction from one anchor: The Collinear Stars.

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

How you win

  1. 1Recognize when Maximum points on a line matches the clues
  2. 2Keep this true after every move: each slope key counts exactly the points sharing that directed line from the anchor
  3. 3Reach the result within O(n squared log coordinate) time

Rules and pressure

  • Target cost: O(n squared log coordinate) time
  • State rule: each slope key counts exactly the points sharing that directed line from the anchor
Lesson 1 of 3

Live algorithm trace

Maximum points on a line

Complete execution
1 of 5

Choose point 1,1 as the current anchor.

1choose each point as anchor
2compute dx and dy to every later point
3divide direction by gcd(abs(dx),abs(dy))
4normalize sign and vertical/horizontal forms
5count equal direction keys
6return largest count plus anchor
anchor = 1,1
Truth to preserve / Cost target
Truth to preserve

each slope key counts exactly the points sharing that directed line from the anchor

Cost target

O(n squared log coordinate) time

For each anchor, reduce every direction vector by its greatest common divisor and normalize its sign. Equal normalized directions identify points on the same line through that anchor.

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