Skip to content

johansenja/sudoku_solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku solver

An OOP sudoku solver written purely in Ruby, with no dependencies. Tested on two different puzzles (very easy and moderate)

Run the tests

rspec

Using this as a library

It's possible, you can require it where needed, and then call Sudoku::Solver.solve(grid), where grid is a 2 dimensional array of numbers, with nil for empty squares, eg.

require "./lib/sudoku_solver"

solver = Sudoku::Solver.new [
  [ 4 ,nil, 6 ,    5 ,nil,  2,    8 ,nil, 9 ],
  [nil,nil,nil,   nil, 4 ,nil,   nil, 3 ,nil],
  [nil,nil,nil,   nil,nil,nil,   nil,nil, 5 ],

  [ 6 ,nil,nil,    8 ,nil,nil,    1 ,nil,nil],
  [ 5 ,nil,nil,   nil, 7 ,nil,   nil, 8 ,nil],
  [ 3 ,nil, 2 ,    9 ,nil, 4 ,   nil, 6 ,nil],

  [nil, 2 ,nil,    6 ,nil,nil,    3 ,nil, 1 ],
  [nil,nil,nil,   nil,  5 ,nil,  nil,nil,nil],
  [ 8 , 3 ,nil,   nil,  9 ,nil,  nil,nil, 2 ],
]
solver.solve # returns same grid, but with nils filled in

About

A zero-dependency OOP sudoku solver in pure Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages