Skip to main content
📜 WAYPOINT LESSON

Checkpoint — What Every Move Preserves

⭐⭐⭐ advanced⏳ 25 min read📍 Lesson 218 of 281

Reduce by |a−b| until one number remains: the invariant is total parity (|a−b| ≡ a+b mod 2). The W nails the math but accumulates in int32 and wraps.

Checkpoint — What Every Move Preserves. The operation replaces a, b with |a − b|; mod 2, |a − b| ≡ a + b, so the total sum's parity is invariant — the answer is the input sum's parity, no simulation. The W is the instructive failure: correct reasoning, wrong integer type. At n = 200000 with values near 10^9 the int32 accumulator wraps (total ≈ 2·10^14), and the parity of a wrapped sum is garbage. Invariants survive only in containers that survive.