Questions tagged [sudoku]

Sudoku (soo-doh-koo) is a number-placement logic puzzle. The objective is to fill a partially constructed 9×9 grid with digits so that each column, each row, and each of the nine 3×3 sub-grids that compose the grid contain all of the digits from 1 to 9.

Completed puzzles are always a type of Latin square with an additional constraint on the contents of individual regions. For example, the same integer may not appear twice in a given row, column, or any of the nine 3×3 sub-regions of the 9×9 playing board. In each puzzle the player must build a solution around a subset of pre-filled digits.

The puzzle was popularized in 1986 by the Japanese puzzle company Nikoli under the name Sudoku, meaning single number. It became an international hit in 2005.

A great deal of literature has been written about solving Sudoku puzzles and they present a very interesting and common subject for mathematicians and programmers. Solving complex Sudoku puzzles may involve combinatorics, group theory, computational complexity, guessing and backtracking. The total number of distinct grids has been calculated as approximately 6.671×1021, so brute-forcing complex puzzles may not always be successful in a desirable timeframe.

The following resources explore the logic and mathematics behind Sudoku puzzles in greater detail:

History:

Number puzzles appeared in newspapers in the late 19th century, when French puzzle setters began experimenting with removing numbers from magic squares. Le Siècle, a Paris-based daily, published a partially completed 9×9 magic square with 3×3 sub-squares on November 19, 1892. It was not a Sudoku because it contained double-digit numbers and required arithmetic rather than logic to solve, but it shared key characteristics: each row, column and sub-square added up to the same number.

On July 6, 1895, Le Siècle's rival, La France, refined the puzzle so that it was almost a modern Sudoku. It simplified the 9×9 magic square puzzle so that each row, column and broken diagonals contained only the numbers 1–9, but did not mark the sub-squares. Although they are unmarked, each 3×3 sub-square does indeed comprise the numbers 1–9 and the additional constraint on the broken diagonals leads to only one solution.

These weekly puzzles were a feature of French newspapers such as L'Echo de Paris for about a decade but disappeared about the time of World War I.

According to Will Shortz, the modern Sudoku was most likely designed anonymously by Howard Garns, a 74-year-old retired architect and freelance puzzle constructor from Indiana, and first published in 1979 by Dell Magazines as Number Place (the earliest known examples of modern Sudoku). Garns's name was always present on the list of contributors in issues of Dell Pencil Puzzles and Word Games that included Number Place, and was always absent from issues that did not. He died in 1989 before getting a chance to see his creation as a worldwide phenomenon. It is unclear if Garns was familiar with any of the French newspapers listed above.

The puzzle was introduced in Japan by Nikoli in the paper Monthly Nikolist in April 1984 as Sūji wa dokushin ni kagiru (数字は独身に限る?), which can be translated as "the digits must be single" or "the digits are limited to one occurrence." (In Japanese,"dokushin" means an "unmarried person".) At a later date, the name was abbreviated to Sudoku(數獨) by Maki Kaji (鍜治 真起 Kaji Maki?), taking only the first kanji of compound words to form a shorter version. In 1986, Nikoli introduced two innovations: the number of givens was restricted to no more than 32, and puzzles became "symmetrical" (meaning the givens were distributed in rotationally symmetric cells). It is now published in mainstream Japanese periodicals, such as the Asahi Shimbun.

Wikipedia Article: http://en.wikipedia.org/wiki/Sudoku

1192 questions
216
votes
6 answers

How to remove convexity defects in a Sudoku square?

I was doing a fun project: Solving a Sudoku from an input image using OpenCV (as in Google goggles etc). And I have completed the task, but at the end I found a little problem for which I came here. I did the programming using Python API of OpenCV…
Abid Rahman K
  • 51,886
  • 31
  • 146
  • 157
88
votes
17 answers

How to generate Sudoku boards with unique solutions

How do you generate a Sudoku board with a unique solution? What I thought was to initialize a random board and then remove some numbers. But my question is how do I maintain the uniqueness of a solution?
guilin 桂林
  • 17,050
  • 29
  • 92
  • 146
32
votes
2 answers

The Dancing Links Algorithm - An explanation that is less explanatory but more on implementation?

I've been working on a Sudoku Solver, my current solver uses the backtracking algorithm but it still takes too long. I'm hoping to get it down to less than a second for most cases. As such, I've decided to rewrite it with the dancing links…
nubela
  • 1
  • 24
  • 75
  • 123
26
votes
3 answers

How to get the cells of a sudoku grid with OpenCV?

I've been trying for the last few days to get a sudoku grid from a picture, and I have been struggling on getting the smaller squares of the grid. I am working on the picture below. I thought processing the image with a canny filter would work fine,…
Malo Maisonneuve
  • 401
  • 5
  • 12
25
votes
6 answers

Sudoku solver in Java, using backtracking and recursion

I am programming a Sudoku solver in Java for a 9x9 grid. I have methods for: printing the grid initializing the board with given values testing for conflicts (if same number is in same line or 3x3 sub-grid) a method to place the digits, one by one,…
Carleton U
  • 283
  • 1
  • 3
  • 7
25
votes
25 answers

A cool algorithm to check a Sudoku field?

Does anyone know a simple algorithm to check if a Sudoku-Configuration is valid? The simplest algorithm I came up with is (for a board of size n) in Pseudocode for each row for each number k in 1..n if k is not in the row (using another…
user18670
  • 301
  • 1
  • 4
  • 6
23
votes
11 answers

Algorithm for solving Sudoku

I want to write a code in python to solve a sudoku puzzle. Do you guys have any idea about a good algorithm for this purpose. I read somewhere in net about a algorithm which solves it by filling the whole box with all possible numbers, then inserts…
Rag Sagar
  • 2,314
  • 1
  • 18
  • 21
19
votes
6 answers

Grade Sudoku difficulty level

I am building a Sudoku game for fun, written in Javascript. Everything works fine, board is generated completely with a single solution each time. My only problem is, and this is what's keeping me from having my project released to public is that I…
vsync
  • 118,978
  • 58
  • 307
  • 400
19
votes
6 answers

Sudoku validity check algorithm - how does this code works?

I was reading a question posted here: Sudoku algorithm in C# And one of the solutions posted was this piece of code. public static bool IsValid(int[] values) { int flag = 0; foreach (int value in values) { if (value…
Rob P.
  • 14,921
  • 14
  • 73
  • 109
18
votes
14 answers

Multi-threaded algorithm for solving sudoku?

I have a homework assignment to write a multi-threaded sudoku solver, which finds all solutions to a given puzzle. I have previously written a very fast single-threaded backtracking sudoku solver, so I don't need any help with the sudoku solving…
Jon
  • 16,212
  • 8
  • 50
  • 62
18
votes
9 answers

Optimizing the backtracking algorithm solving Sudoku

I'm hoping to optimize my backtracking algorithm for my Sudoku Solver. What it does now: The recursive solver function takes a sudoku puzzle with various given values. I will scour through all the empty slots in the puzzle, looking for the slot…
nubela
  • 1
  • 24
  • 75
  • 123
17
votes
14 answers

Code Golf: Validate Sudoku Grid

Introduction A valid Sudoku grid is filled with numbers 1 to 9, with no number occurring more than once in each sub-block of 9, row or column. Read this article for further details if you're unfamiliar with this popular puzzle. Challenge The…
moinudin
  • 134,091
  • 45
  • 190
  • 216
16
votes
6 answers

Building a GUI for a Sudoku Solver (Complete with ASCII Example)

. OVERVIEW, SAMPLE Hello everyone, I have created a basic Sudoku solver that can solve most problems fairly quickly. I still have a lot of work ahead of me to make it solve even the hardest problems, but I'd like to try to implement a basic JFrame…
Justian Meyer
  • 3,623
  • 9
  • 35
  • 53
14
votes
4 answers

Is there any algorithm that can solve ANY traditional sudoku puzzles, WITHOUT guessing (or similar techniques)?

Is there any algorithm that solves ANY traditional sudoku puzzle, WITHOUT guessing? Here Guessing means trying an candidate and see how far it goes, if a contradiction is found with the guess, backtracking to the guessing step and try another…
justin
  • 225
  • 2
  • 7
14
votes
7 answers

Creating sudoku initial boards

Is there an algorithm or way I can get initial state sudoku puzzles for a sudoku game. Preferably with the ability to have different levels of difficulty?
Devin
  • 141
  • 1
  • 3
1
2 3
79 80