After a wrong answer, it is easy to begin editing immediately: change an inequality, widen an integer type, add a case. Some of these edits work. They also encourage debugging by superstition.
The first objective should be a separating input: a case for which the intended answer and the program’s answer differ for a reason that can be explained.
Search by assumption
List the claims the solution depends on. An interval greedy rule may assume that choosing the earliest endpoint never blocks a better future. A graph traversal may assume that the first arrival is final. A dynamic program may assume that two histories with the same stored state have identical futures.
Build an input that places pressure on one assumption at a time.
Minimize the witness
A large random failure proves disagreement but may hide the cause. Remove elements, edges, and operations while preserving the failure. The smallest witness often reveals the missing distinction directly.
For a synthetic interval problem, six intervals may fail. After reduction, three may be enough: one tempting early choice and two later choices it excludes. That three-interval witness is an explanation, not merely a test.
Predict before running
Write the expected answer and the program’s predicted path before execution. If the prediction is wrong, the mental model of the code also needs repair. This step prevents repeated runs from replacing reasoning.
Keep the counterexample
Add the minimized witness to a local regression set with a one-line label: “first arrival is not final” or “state omits remaining capacity.” The label preserves the lesson after the code changes.
Sometimes no small witness appears because the implementation, not the idea, is wrong. The same process still narrows the search: compare the proof’s obligations with assertions at the corresponding code boundaries.
A verdict is the beginning of diagnosis. The counterexample turns it into evidence.