Sudoku Solver

Extreme

Complex Logic (Trial and Contradiction)

Last resort strategy that tests candidates and eliminates those that lead to contradictions.

Complex Logic (also known as Trial and Contradiction, Bifurcation, or Nishio) is the ultimate fallback strategy when all other techniques fail. It tests a candidate by temporarily assuming it's correct, then checks if that assumption leads to an impossible state.

If a contradiction occurs, the assumption was wrong, and we can safely eliminate that candidate.

Interactive Example

1 2 3 4 5 6 7 8 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
5
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1
1 2 3 4 5 6 7 8 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
9
1 2 3 4 5 6 7 8 9
1
1 2 3 4 5 6 7 8 9
4
1 2 3 4 5 6 7 8 9
6
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
5
1 2 3 4 5 6 7 8 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
6
1 2 3 4 5 6 7 8 9
7
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
9
1 2 3 4 5 6 7 8 9
1
1 2 3 4 5 6 7 8 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
6
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
5
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
2
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
3
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
7
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
2
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9
5
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9

Click "Apply Logic" to see the strategy in action.

Real Example Walkthrough

In the example puzzle above, the solver encounters a situation where standard strategies don't work:

The Test: 1. Cell R1C1 has candidates {7, 9} 2. The solver asks: "What if R1C1 = 7?"

The Process: 1. Temporarily set R1C1 to 7 2. Attempt to solve the puzzle from this state 3. Result: The puzzle becomes unsolvable (contradiction)

The Conclusion: - Since R1C1 = 7 leads to an impossible state - R1C1 cannot be 7 - Eliminate 7 from R1C1

Result: R1C1 must be 9.

How It Works

The Core Logic

This strategy uses proof by contradiction:

1. ASSUME: Candidate X is in cell A 2. TEST: Try to solve the puzzle with this assumption 3. RESULT: Either... - ✅ Solvable → X might be correct (no elimination) - ❌ Unsolvable → X is definitely wrong → ELIMINATE X

The Algorithm

For each unsolved cell: For each candidate in that cell: 1. Make a copy of the grid 2. Set the candidate as the cell's value 3. Run a fast solver to test solvability 4. If "unsolvable" → eliminate that candidate 5. Stop after first successful elimination

Priority Order

The solver tests candidates efficiently:

Priority Cell Type Why This Order
1st Bivalue cells (2 candidates) Most likely to force quick contradictions
2nd All other cells Fallback for more complex situations

Testing bivalue cells first is efficient because: - They have fewer candidates to test - Eliminating one candidate solves the cell immediately - Contradictions propagate faster

Understanding Contradictions

A contradiction occurs when the puzzle becomes impossible:

Contradiction Type Example
Empty cell A cell has no valid candidates left
Duplicate in region Same number appears twice in a row/column/box
No place for value A value has no valid cell in a region

When any of these occur, the assumption that caused it must be wrong.

Example Contradiction Chain

Let's trace what might happen when assuming R1C1 = 7:

Step 1: Set R1C1 = 7 Step 2: R1C7 can't be 7 (same row) → R1C7 = 9 (only option) Step 3: R4C7 can't be 9 → R4C7 = ... (propagates) Step 4: Eventually... Step N: Some cell loses all candidates → CONTRADICTION!

The solver doesn't track every step—it simply checks if the puzzle can be solved. If not, the original assumption was wrong.

When Complex Logic Is Used

This strategy is a last resort, applied only when everything else fails:

Before Complex Logic Examples
All basic strategies Naked Single, Hidden Single
Intersection strategies Pointing, Box/Line
Subset strategies Naked Pair, Hidden Triple
Fish strategies X-Wing, Swordfish
Wing strategies Y-Wing, XYZ-Wing
Chain strategies XY-Chain, X-Cycle
Uniqueness strategies Unique Rectangle, BUG

Only after ALL these strategies produce no eliminations does Complex Logic activate.

Is It "Cheating"?

There's debate in the Sudoku community about trial-and-error:

Perspective Argument
Purists "Real" strategies should be pattern-based, not guessing
Pragmatists If it produces correct eliminations logically, it's valid
Our View It's still logic—just computationally verified rather than pattern-matched

Complex Logic is not random guessing. It systematically tests hypotheses and only eliminates candidates that are provably impossible.

Comparison: Complex Logic vs Chains

Aspect Chain Strategies Complex Logic
Method Follow logical links manually Automated exhaustive testing
Speed Fast (pattern matching) Slow (full solve attempts)
Proof Step-by-step deduction Verified by solver
Human-friendly Yes (can be followed) No (too many steps)

Chain strategies like XY-Chain or X-Cycle essentially do the same thing as Complex Logic, but they find the contradiction through recognizable patterns rather than brute-force testing.

How the Solver Tests Candidates

Our solver uses a highly optimized approach:

  1. Make a copy of the current grid
  2. Set the candidate as the cell's value in the copy
  3. Run a fast solver to check if the puzzle can be solved
  4. If unsolvable → the candidate is impossible → eliminate it

Key features: - Fast backtracking solver: Uses optimized algorithms to quickly detect contradictions - Timeout protection: Prevents getting stuck on extremely complex positions - One elimination at a time: Returns after first successful elimination for efficiency

Tips for Beginners

Manual Approach

If you want to use Complex Logic by hand:

  1. Pick a bivalue cell — Choose a cell with only 2 candidates
  2. Assume one value — Write it in lightly with pencil
  3. Propagate carefully — Apply naked singles and other simple strategies
  4. Watch for contradictions — Empty cells, duplicates, etc.
  5. If contradiction found — Erase and eliminate that candidate
  6. If stuck (no contradiction) — Erase and try the other candidate

When to Use It

  • When you've tried every other strategy you know
  • When the puzzle is rated "Extreme" or "Expert+"
  • When you just want to finish the puzzle!

Difficulty Considerations

Puzzle Level Complex Logic Needed?
Easy Never
Medium Never
Hard Rarely
Expert Sometimes
Extreme Often

Puzzle designers typically avoid creating puzzles that require Complex Logic, but some extremely difficult puzzles have no other solution path.

Why It's Called "Complex Logic"

The name reflects that: - The underlying logic is sound (proof by contradiction) - The chain of deductions is complex (too long to trace manually) - It handles situations too complicated for pattern-based strategies

It's not "guessing"—it's verified logical deduction that happens to require computational assistance.

Common Misconceptions

"It's just guessing"

No. Every elimination is proven impossible. We don't "guess" the answer—we prove what's NOT the answer.

"Any puzzle can be solved this way"

Yes, but... Complex Logic can solve any valid Sudoku, but it's inefficient. Named strategies are faster and more elegant.

"I should use it first to save time"

Bad idea. Named strategies are usually faster and help you learn. Complex Logic is a last resort, not a shortcut.

Related Strategies

Strategies That Do Similar Things (Pattern-Based)

  • XY-Chain — Finds contradiction paths through bivalue cells
  • XY-Cycle — Loop that creates contradiction
  • X-Cycle — Single-candidate contradiction loop
  • Forcing Chains — General chain-based deductions

Strategies to Try First

  • Simple Coloring — Two-color candidate tracking
  • 3D Medusa — Extended coloring
  • W-Wing — Bivalue cell pair pattern
  • Empty Rectangle — Box-line interaction pattern (Coming Soon)

Uniqueness Strategies