0PricingLogin
Competitive Programming Academy · Lesson

Cycle Detection in Simulations

Skip ahead when the state repeats.

When Steps Repeat

Some simulations ask for the state after a huge number of steps, like a trillion. Stepping one at a time would never finish in time. ⏳

States Are Finite

If the number of possible states is limited, the simulation must eventually revisit one. From there it repeats forever in a cycle.

All lessons in this course

  1. Model State and Step Forward
  2. Grid Walks and Direction Vectors
  3. Cycle Detection in Simulations
  4. Tame the Tricky Edge Cases
← Back to Competitive Programming Academy