Created: 2011-07-09 20:46
Updated: 2014-06-15 09:58

Sudoku generator and solver

Running web demo

  • play on-line
  • print sudoku book

Usage from command line

Solve sudoku from file:

sudoku.rb <filename>
sudoku.rb <filename> <timelimit (0==off, -1==inf)>

Generate new sudoku:

sudoku.rb <dimension> [level=<1..5>] [alphabet|numeric] [time limit]


Create new sudoku:

require 'sudoku'

level = 3
dimension = 9
type = :numeric
sudoku = level, dimension, type

Solve sudoku with time limit 60 secods:

require 'sudoku'

sudoku = Sudoku::Grid.read_file(ARGV[0]), 60


Solver firstly tries solve a grid with rules before brute force method. Brute force method can be limited with time.

Implemented rules:

  • Only choice rule
  • Single possibility rule
  • Two out of three
  • Only square rule
  • Hidden single
  • Naked Twins exclusion rule
  • Hidden Twins exclusion rule
  • Subgroup exclusion rule
  • X-Wing exclusion rule
  • Sword Fish rule
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more