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
3
votes
1 answer

How to trace backtracks of clpfd in prolog?

I am making a sudoku solver with prolog using clpfd library. I have to trace the backtracks and every squares labeled with row and column and the number it gets in the following form: (1 ,1 ,1) (9 ,2 ,1) BT (5 ,2 ,1) …
Kosar Kazemi
  • 65
  • 1
  • 6
3
votes
3 answers

Java - Sudoku (backtracking) ' is place valid' method explanation needed.

I've this Sudoku code that's done using backtracking and I understand everything, except few lines of code which I ask to be explained. This is the whole code. public class Sudoku { static int N = 9; static int grid[][] = { { 3, 0, 6, 5,…
Seinfeld
  • 433
  • 7
  • 24
3
votes
6 answers

Finding characters in a string that occur only once

I'm writing an algorithm in PHP to solve a given Sudoku puzzle. I've set up a somewhat object-oriented implementation with two classes: a Square class for each individual tile on the 9x9 board, and a Sudoku class, which has a matrix of Squares to…
Magsol
  • 4,640
  • 11
  • 46
  • 68
3
votes
1 answer

An alldifferent for tuples

I'm trying to solve a sudoku with the viewpoint that every number has 9 positions. This is the representation for my sudoku: From the table you can read that number 5 has following positions (Row,Col) in the sudoku: (2,8),(4,2),(6,5). When I…
Stanko
  • 4,275
  • 3
  • 23
  • 51
3
votes
1 answer

How to apply openMP to a C++ function to validate all rows of a sudoku puzzle solution?

I am designing a program that will test to see whether a valid sudoku puzzle solution is given to the program or not. I first designed it in C++ but now I want to try to make it parallel. The program compiles fine without errors. First I had to…
3
votes
4 answers

How do I verify the validity of a Sudoku grid in Java?

I'm trying to create a Sudoku program that checks if a Sudoku grid is valid. I figured out how to check that each row is valid, as well as for each column. However, I'm having trouble coming up with code to check each of the 9 small boxes in the…
Daveguy
  • 255
  • 3
  • 11
3
votes
0 answers

Solve a single cell in Sudoku

I have a method for solving an entire Sudoku puzzle (checking for empty cells, and filling those cells with the current element in its corresponding position in the puzzle solution array) and it works great. I am having a problem implementing an…
user5560769
3
votes
3 answers

Brute-force sudoku solver: backtracking?

An implementation of a brute-force algorithm to solve Sudoku puzzles fails if a cell is discovered in which placing any of the digits 1-9 would be an illegal move. The implementation is written in C, with the board represented by a 9x9 array. The…
Yktula
  • 14,179
  • 14
  • 48
  • 71
3
votes
2 answers

Sudoku solving/generating algorithm in PHP

I'm having trouble with a specific part of my algorithm and was hoping someone has an idea what I'm doing wrong. My program basically works like this: Create 81 empty cells, fill each cell step per step while checking if it's valid there. I have 3…
gempir
  • 1,791
  • 4
  • 22
  • 46
3
votes
1 answer

Prolog - jigoku solver - run time

I'm a total newbie to Prolog (as in: I've only done the Prolog chapter in 7 languages in 7 weeks), so general comments to any of the code below are very welcome. First of all: What is a jigoku? It's like a sudoku, except that you get an empty grid,…
liesb
  • 53
  • 7
3
votes
2 answers

Solving Sudoku Programmatically

I'm attempting to solve a Sudoku puzzle using Java. Currently this class is unable to solve a Sudoku properly. This class attempts to look for the 0s (blank spaces) within the 9x9 matrix and notes down the position of the 0 in a list for later…
HelloWorld
  • 83
  • 1
  • 8
3
votes
0 answers

OpenCv Sudoku Grabber

I'm trying to extract the sudoku table from this image but I'm new to OpenCv world and I'm not having success. Does anyone of you have some suggestion to guide me to the correct solution?
fitzbutz
  • 956
  • 15
  • 33
3
votes
1 answer

Sudoku board check algorithm - is there anything else to check other than duplicates?

I made an algorithm to check if a board is illegal, it checks for duplicates in the rows, columns and sectors, it worked well for duplicates but then after a few games I got to the following board: Which doesn't have a solution (there are no…
shinzou
  • 5,850
  • 10
  • 60
  • 124
3
votes
1 answer

sudoku solver with constraints and backtracking in python

I realise that this problem has been discussed a lot here, and I've read everything. However, my program doesn't work. Well, it solves grids of easy and medium diffuculty, but when it comes to some difficult puzzles it seems to get into an infinite…
3
votes
3 answers

Otsu Thresholding on a Sobel Filtered Image gives different Results

I'm creating a Sudoku solving application on an Android platform and I've run into an issue when processing the image. I'm trying to find the horizontal lines of the puzzle using OpenCV using a Sobel filter and then thresholding with the Otsu…