Home page


Sudoku Index Page

Introduction

Sudoku is a popular puzzle (at least among train commuters in London). The object is to fill in a 9x9 grid of numbers while following a few simple rules. This set of pages grew out of my interest in producing a script that would solve them automatically (as I find doing it by hand rather tedious).

The site is divided into the following sections.

  • The problem.
  • Interactive solver: An interactive Sudoku solver implemented in Javascipt. This allows you to solve the original 9 x 9 puzzle and a number of variants from 4 x 4 up to 16 x 16. You can also use it to create puzzles by adding digits incrementally until you find a solution.
  • Variants: Explains how the the original 9 x 9 version can be extended to other sizes.
  • Create Sodukos: This page uses Javascript to create puzzles for you to solve. It can create the classic 9 x 9 puzzle and a number of the variants.
  • How to solve them: A walk-through and Python script. The Javascript used in the interactive version was developed from scratch so it is very different from the Python version, though is does use the same basic ideas.
  • Python source code: Python scripts to download. You can download the javascript used on the interactive page from there.

Updates:

Feb 2014 - Added interactive Javascript puzzle creator.
Dec 2013 - Added interactive Javascript version.

The Problem

The original 9x9 puzzle has a 9 by 9 square grid. Some squares contain numbers, most are blank. The objective is to fill in the missing numbers to complete the whole grid. There are a few constraints though:

  1. Every row must contain each of the numbers 1-9 exactly once.
  2. Every column must contain each of the numbers 1-9 exactly once.
  3. Each of the nine 3x3 sub-sections (highlighted in the example below using a checkerboard shading pattern) must contain each of the numbers 1-9 exactly once.
    19 4 
  48  6  
75      2
 9 1 2  4
     3   
5  4 6 3 
8      73
  6  84  
 1 29    

These rules are easy to generalise to other sized squares as we will see on the variants page. We can also add additional constraints, such as requiring the two diagonals to contain 1-9 too.

The solution

This is the solution to the above example where you can verify that the constraints are met. Proving that this is the only solution is a trickier problem.

268719345
134825697
759364182
397182564
642953718
581476239
825641973
976538421
413297856

(c) John Whitehouse 2013