Beyond "It Passes"
G21: The danger of trial-and-error coding is producing code you don't understand. You add an if statement, tests pass. You add a magic + 1, tests pass again. Eventually the tests are green but you cannot explain why any specific line is there. This produces fragile code: it works for the test cases you have, but breaks on edge cases you didn't think of, because you never understood the invariant.
How Understanding Simplifies
When you truly understand an algorithm, the special cases and extra if branches disappear. The trial-and-error version is always longer than the understood version. The test: can you explain every line out loud, including why each branch exists and what invariant it protects? If you cannot, refactor until you can.
Code Challenge
Replace the trial-and-error algorithm with a version where every line can be explained.
Key takeaway
G21: Don't commit code you can't explain. If you can't describe why every line exists, the algorithm is controlling you — you're not controlling it.