Modular Arithmetic and Greatest Common Divisors (GCD): The Mathematics of Bombing Stride
How changing the bombing interval from #4 to #2 alters spatial coverage density, sweep speed, and modular periodicity
Dwarf's bombing interval is controlled by #4 in ADD.AB #4, $3 on line 1 (0000). With #4, bombs land on 0007 and 0011, skipping right over Address 0005.
🎯 Your Task Change the highlighted A (Left Value) on row 0000 from #4 to #2 and press [PLAY] to carpet-bomb every 2 cells (hitting both 0005 and 0007)!
1. The Fundamental Trade-Off: Mesh Density vs. Sweep Speed
In Step 20, you modified Dwarf's additive stride on row 0000 from "#4" to "#2", tightening its bombing pattern so that bombs landed every 2 cells (0005, 0007, 0009...) instead of every 4 cells.
When designing a bomber in CoreWar, choosing the step size (stride) confronts you with one of the classic optimization trade-offs in search theory: Spatial Density versus Sweep Speed. - A Small Stride (e.g., #2): Casts a very fine net. Any enemy program that is at least 2 lines long is guaranteed to be hit on the very first pass! However, covering an 800-cell arena 2 cells at a time requires 400 shots (1,200 cycles), meaning your bombs travel slowly across space. - A Large Stride (e.g., #8 or #16): Sweeps across the entire arena at lightning speed, reaching distant enemies quickly. However, the wide gaps between bombs leave safe pockets where smaller enemies can hide unscathed.
Stride #4 (Mod-4): [0003] ──► . . . 💥(0007) . . . 💥(0011) (3-cell safe gap between bombs)
Stride #2 (Mod-2): [0003] ──► . 💥(0005) . 💥(0007) . 💥(0009) (Only 1-cell gap! Dense carpet)2. The Mathematics of the Ring: The GCD(CoreSize, Step) Theorem
Here we encounter one of the most elegant applications of number theory in computer science. In a circular memory ring of size N (where N = 800 in the Academy and N = 8,000 in the Laboratory), if a pointer advances by a constant step size S on every iteration, which cells will it visit before repeating?
Number theory gives us the exact formula via the Greatest Common Divisor, GCD(N, S): - The minimum gap between visited cells after a full cycle is g = GCD(N, S). - The total number of unique cells visited before the pattern repeats is N / GCD(N, S).
Let's test this theorem on our 800-cell Academy core: - When Step S = 4: GCD(800, 4) = 4. The bomber visits 800 / 4 = 200 unique cells spaced 4 addresses apart (Mod-4 bombing). - When Step S = 2: GCD(800, 2) = 2. The bomber visits 800 / 2 = 400 unique cells spaced 2 addresses apart (Mod-2 bombing).
What if you choose a step size S that is coprime to 800 (meaning GCD(800, S) = 1), such as S = 3, S = 7, or S = 253? Because GCD(800, S) = 1, the pointer will visit ALL 800 cells of memory (800 / 1 = 800) without ever repeating an address until every single cell in the universe has been hit! (Of course, a Mod-1 step will eventually walk right across your own code at 0000–0002 unless you design a self-preservation mechanism, such as switching to a core-clear carpet bomb right before the pointer wraps back onto your own body.)
3. Optimal Step Sizes ("Optima Numbers") in Competitive CoreWar
In competitive CoreWar tournaments on an 8,000-cell core, champion warriors rarely use small sequential steps like #2 or #4. Why? Because a sequential step sweeps memory like a slow windshield wiper—if the enemy happens to spawn at Address 7500, a sequential bomber takes thousands of cycles to reach them.
Instead, tournament designers use mathematically derived constants known as "Optima Step Sizes" (such as #2364 or #3044 for Mod-4 on an 8,000-cell core). Because GCD(8000, 2364) = 4, a step of #2364 still guarantees safe Mod-4 immunity for a 4-line warrior, while scattering bombs evenly across every quadrant of the arena from the very first few shots! Behind that single number in the A-field lies a rich intersection of number theory, linear congruential generators (pseudo-random number theory), and search optimization.
🔒 MISSION CLEAR Unlocks the Full Lecture Note
Complete the experiment in the simulator above to automatically unlock the full deep-dive article—or click below to read the full text immediately.