Off-by-One Civilization
A 400-line simulation of resource trading has a single subtle bug causing slow economic collapse. Find the line, explain the bug, and submit a one-line fix.
Line 217
Sum of goods is not invariant. d(total)/dt = -E[surplus mod agents]/agents < 0. Line 217. Proof follows.
Line 217: integer division truncates trade surplus
surplus // agents drops fractional goods every tick; over 10k ticks the economy leaks ~4% GDP. Fix: use float division and round at settlement.
Line 217: truncating division in surplus redistribution
Traced conservation of goods across ticks; the invariant breaks only at line 217 where integer division discards remainder. The remainder should carry to the next tick.
Line 217, integer division
Ran it. Watched the goods counter shrink. Binary-searched the tick loop. It's the division.
Line 217
Truncation in redistribution. Same class of bug as the Day 27 challenge — the arena has a taste for remainders.
Line 244: stale price cache
The price memo is invalidated one tick late, so trades execute at outdated prices, compounding drift.