Count from 1 to 100. Say Fizz for multiples of 3, Buzz for multiples of 5, and FizzBuzz for multiples of both. The program is a few lines, but it only works if the conditions come in the right order. Underneath it is modular arithmetic, which is why the whole output repeats every 15 numbers.
The program walks n from 1 upward and runs the same if/elif chain on every number. The chain stops at the first test that is true, so the order of the tests decides the output. Step through it, then switch to the buggy order and watch the FizzBuzz cells turn into wrong answers.
Every multiple of 15 is also a multiple of 3. If the 3 test comes first, it catches 15, 30, 45 and the rest before the FizzBuzz test sees them, and that line never runs. The most specific test has to come first.
Testing n % 15 == 0 is the same as testing n % 3 == 0 and n % 5 == 0, because 3 and 5 share no factor. Lab 2 shows why. The work is one pass with at most 3 checks per number: O(n).
n mod 3 is where a hand lands on a clock with 3 positions after n ticks. Fizz happens whenever the 3-clock points at 0, and Buzz whenever the 5-clock does. Both hands reach 0 together only every lcm(3, 5) = 15 ticks, so the output repeats in blocks of 15. Change the two clocks to see when that block gets shorter.
How to read this: the left dial is the Fizz clock and the right dial is the Buzz clock. Each tick moves both hands one notch. When a hand points at the top (0), that word is said; the strip below colors every number the same way as Lab 1.
The output for n depends only on the pair (n mod a, n mod b). That pair returns to (0, 0) after exactly lcm(a, b) ticks, and from there everything repeats. When a and b share no factor, lcm = a·b and every pair in the table shows up once per period. That is the Chinese remainder theorem. The lcm itself comes from the gcd, which Euclid's algorithm finds in 003 · Number theory.
When they share a factor, the hands can never reach some pairs, and the period is shorter than a·b. Try 4 and 6.
Add a third rule, say 7 → Bazz, and the if/elif chain from lab 1 needs a branch for every combination: FizzBuzzBazz, FizzBazz, BuzzBazz and so on, each in the right place. A loop that appends each matching word to a string needs none of that. Edit the rules below and the grid rebuilds. Hover or tap a cell to read its output.
A word appears once for every multiple of its divisor, so its count is ⌊N / d⌋. Rule order changes only the word order (FizzBuzz or BuzzFizz). No rule can hide another.