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

how is sudoku np-complete?

how is Sudoku an np-complete problem? according to wiki, to be classed as an np-complete problem it must satisfy 2 conditions problem must be in np every other problem in np must be reducible to given problem in polynomial time how is the second…
Ashish K
  • 325
  • 2
  • 6
  • 12
2
votes
1 answer

What is the Big-O of Sudoku using brute force backtracking?

I was wondering what the Big-O of a simple brute force backtracking Sudoku solving algorithm was. Sudoku has 4 constraints: cell - one cell can contain one number max region - numbers in the region must be all different row - numbers on the same…
Tai
  • 101
  • 1
  • 1
  • 10
2
votes
1 answer

Backtracking algorithm to solve Sudoku

I've been trying to implement a backtracking algorithm to solve Sudoku in java console application. I've never implemented the algorithm before, and probably looking at few youtube videos was not enough, because it does not seem to work as I think…
DR29
  • 121
  • 2
  • 12
2
votes
1 answer

Complexity of Dancing links

I'm writing a sudoku solver and thinking about an algorithm to implement it in. I know backtracking has a time complexity of O(n^m) where n is the number of possibilities for each square and m is the number of spaces that are blank. But I couldn't…
user3666471
  • 907
  • 11
  • 24
2
votes
3 answers

Python - Streamlining sudoku solver code

I am writing a script to efficiently solve a sudoku puzzle, but there's one part of my code that I think is extremely ugly and want to streamline. def square(cell): rows='ABCDEFGHI' cols='123456789' cell_row = cell[0][0] cell_col =…
ggordon
  • 259
  • 1
  • 3
  • 16
2
votes
1 answer

Python -- IndexError: list index out of range (sudoku solver program)

I'm sorry if this code is not the easiest to follow. So I have a two dimensional list board with 9x9 dimensions (a sudoku board). In one of the lines in the solve function I check to see if row <= 8 and column <=8: and then call the add1 function.…
conjenks
  • 409
  • 1
  • 6
  • 18
2
votes
0 answers

Sudoku Backtracking - Order of walking through fields by amount of possible values

I've created a backtracking algorithm for solving Sudoku puzzles which basicly walks through all the empty fields from left to right, top down respectively. Now I need to make an extended version in which the order in which the algorithm walks…
user2999349
  • 859
  • 8
  • 21
2
votes
1 answer

Backtrack sudoku in haskell

I'm trying to build a backtrack sudoku solver in Haskell. But I'm stuck at one of the final points. I created a function called nextBoards which returns all possible soduko boards where the next empty place is filled in with the possible values. Now…
user4424299
2
votes
1 answer

Sudoku Solver in SML with Backtracking

I'm working on creating a Sudoku Solver with SML/NJ. I've got all of the functions in place to actually manipulate the input data (check for legality of rows, forcing the empty spaces, etc) but I'm having trouble with the backtracking part. I came…
Andrew Brooke
  • 12,073
  • 8
  • 39
  • 55
2
votes
0 answers

Sudoku Solver problems (backtracking algorithm) runs endlessly

I'm sort of new to Java. Here is my stab at trying to make a Sudoku solver. As of right now this doesn't have a GUI, to enter the problem you have to modify the code itself. Usually the the program completes the Sudoku in around 30 milliseconds…
Dr. K1NG
  • 29
  • 1
  • 7
2
votes
1 answer

How best to Implement naked single and hidden single in scheme

I am writing a sudoku solver in scheme. I represent the board cells as a 3x3 vector of 3x3 vectors with a list of the candidates numbers in each cell. So for example a blank board and updating one of its cells is (define blank-board-cell…
user2175783
  • 1,291
  • 1
  • 12
  • 28
2
votes
2 answers

Sudoku with python

def print_map(sudoku_map): for line in sudoku_map: print(line) print("\n") #it will determine whether there is a same a in row or not def search_row(sudoku_map_search, a, row): for i in range(9): if…
ihsancemil
  • 432
  • 5
  • 16
2
votes
2 answers

How to work with maybe to detect sudoku values

I want to form a list of Bools for if values suite a Sudoku format. i.e either Nothing or Just x where (1 <= x <= 9). Here is my code below: import Data.Ix import Data.Maybe isSudokuValues :: (Ix a, Num a) => [Maybe a] -> [Bool] isSudokuValues list…
Hakim Marley
  • 330
  • 2
  • 5
  • 19
2
votes
1 answer

Segmentation fault, first time with 2D arrays

I am working with 2D arrays for the first time for a sudoku checker program; below is my code. My program compiles without error, but when I run it, it gives me a segmentation fault. It has been a while since I last coded, so I am unsure what I'm…
Jude
  • 449
  • 1
  • 7
  • 17
2
votes
2 answers

Javascript recursion for sudoku?

I am working on a sudoku puzzle, so I put all the items in an array. So, whenever I get a invalid number, I have to call a function recursively, but I cant do that. I can't understand what the problem id. My methods are: function checkValidity(x,y)…
user3928524