October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Verify a Combinatorics Solution with Brute-Force Tests

Use a simple independent enumerator to compare a combinatorics solution on small, fully specified inputs—and understand why passing tests is not a proof.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Write a small, direct enumerator for the objects in your problem, then compare its count with your formula or optimized algorithm on a stated set of small inputs. This is a practical way to find errors, not a proof that the solution works for every input: the check is only as reliable as the definition, reference enumerator and cases you actually test.

1. Define exactly what is being counted

Before writing code, specify what counts as one object and when two objects are considered the same. These choices change the answer, so an enumerator cannot check a problem whose conventions remain implicit.

  • Ordering: Are sequences with the same elements in a different order distinct?
  • Repetition: Can an element appear more than once?
  • Labels: Are objects with different labels distinct even if their shapes or values match?
  • Constraints: What conditions make a candidate valid?
  • Edges: What should happen at the smallest meaningful size, and is an empty object allowed?

Use the same conventions in the proposed solution and the test. If they disagree, matching or mismatching counts may reflect an interpretation difference rather than an implementation error.

2. Build a simple, independent reference enumerator

For tiny inputs, choose the most transparent direct method: generate candidate objects, test each against the definition, and count the valid ones. Prefer clarity over speed. The enumerator’s job is to provide a comprehensible reference result, not to handle large inputs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep it as independent as practical from the solution under test. If both use the same recurrence, algebraic transformation or pruning rule, a shared mistake can make their answers agree. Directly listing candidates and filtering them is often a useful contrast to a compact formula or optimized implementation.

For example, if the problem counts arrangements, generate each candidate arrangement under the stated rules and count the valid arrangements. Make sure the generation step neither omits valid cases nor counts the same object multiple times under the problem’s definition.

3. Choose a finite test grid you can enumerate completely

Test a run of small parameter values that includes the minimum meaningful sizes and boundary configurations. Select a limit the direct enumerator can cover in full; enumeration can grow quickly, and there is no benefit in claiming coverage beyond what you ran.

  • Include the smallest allowed inputs and any meaningful empty or singleton cases.
  • Cover boundaries where constraints or formulas change behavior.
  • Record the exact range and any excluded cases, so the extent of the check is clear.

For each input in the grid, run both methods on precisely the same parameters and conventions. Python’s official unittest documentation describes test cases and assertions for expressing comparisons and organizing them into test suites. A particular framework is optional; the important part is that disagreement produces a visible failure.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

4. Compare the results and preserve counterexamples

For every selected input, compute the reference count and the proposed answer, then assert that they are equal. When they differ, keep the smallest failing input and, if feasible, the concrete objects the enumerator generated. Inspect definitions, duplicate handling, order conventions and boundary conditions before changing the formula.

Once you understand a mismatch, reduce it to a minimal example and retain it as a regression test. That way, a later change cannot silently reintroduce the same error.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

5. Add hand checks and generated properties

Hand-checkable cases

Work through a few tiny inputs by hand and compare those counts with both programs. Where the problem has known structural checks—such as a symmetry or a recurrence—check those too. They offer additional ways to catch mistakes, but they do not replace direct enumeration.

Property-based tests

Property-based testing can broaden the set of cases you inspect. The Hypothesis documentation describes strategies for generating inputs and gives comparison with a slower, clearly correct implementation as an example use. You can use a strategy to generate valid small inputs, then check that the optimized solution agrees with the reference enumerator or satisfies a suitable property.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Generated tests are not automatically exhaustive. Hypothesis explains that runs are generally bounded by settings and behavior; for finite strategies, it may detect search-space exhaustion and stop, but its tracking is imperfect. Treat generated cases as a complement to a deliberately chosen finite grid, not as universal coverage. See How many times will Hypothesis run my test? for the framework’s explanation.

What a passing brute-force check does—and does not—show

If the enumerator and solution correctly represent the problem, exhaustive agreement over a finite grid shows that they agree on the inputs in that grid. It is evidence against mistakes in those tested cases. It does not establish agreement for untested sizes or prove a statement quantified over all input sizes. That stronger conclusion requires a mathematical proof or a formal verification argument.

When reporting a check, state the tested domain, whether every case in it was enumerated, and any cases omitted. Keep sampled or generated testing distinct from exhaustive testing. In all cases, the conclusion depends on the reference enumerator correctly implementing the intended definition.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.