Class: Xudoku::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/xudoku/generator.rb

Overview

Generates a new Sudoku puzzle by progressively removing clues from a solved board.

Starts by solving a blank board to obtain a complete solution, then repeatedly removes digits at random, keeping only removals that leave the puzzle uniquely solvable. The process continues until no further digits can be removed without introducing multiple solutions.

Returns:

  • (Result)

    a result containing the minimal puzzle and its solution

Constant Summary collapse

SOLVE_ATTEMPTS =
5

Instance Method Summary collapse

Instance Method Details

#generateResult

Generates a new Sudoku puzzle by solving an empty board and removing clues.

Returns:

  • (Result)

    a result containing the generated puzzle and its solution



19
20
21
22
23
24
# File 'lib/xudoku/generator.rb', line 19

def generate
  solved = Solver.new(Board.empty).solve
  puzzle = _generator(solved)

  Result.new(solution: solved, puzzle: puzzle)
end