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

Efficient permutation tree algorithms

I was attempting to write an algorithm for solving any sudoku. However, my original approach was flawed as I failed to realise that a well-formed sudoku should only have one solution. As such, the resultant algorithm is not optimised for sudoku…
djtango
  • 81
  • 5
4
votes
3 answers

How to getText() like input[i][j].getText(); (for sudoku solver in netbeans)

I want to get the text in int form from 81 text fields arranged in a 9 X 9grid but don't want to do it individually. I tried to put it in a loop but the problem is that the text field name has to be shown in a[i][j] form. for (i = 0; i < 9; i++) { …
GtlsGamr
  • 71
  • 7
4
votes
1 answer

How to generate 5x5 sudoku puzzle?

I have written algorithm to generate 5x5 sudoku puzzles. Here is how it works. On my 5x5 sudoku there are only two contraints. There can be only item of one kind in every row and column. Generate random position(0,4) If position is filled go back…
zarcel
  • 1,211
  • 2
  • 16
  • 35
4
votes
1 answer

What's the worst-case valid sudoku puzzle for simple backtracking brute force algorithm?

The "simple/naive backtracking brute force algorithm", "Straightforward Depth-First Search" for sudoku is commonly known and implemented. and no different implementation seems to exist. (when i first wrote this question.. i wanted to mean we could…
farter
  • 76
  • 5
4
votes
1 answer

Z3 Sudoku Solver

I was on the site rise4fun a few weeks ago and they had a python code that converted a sudoku puzzle input file to z3. I checked again today and the file is gone, and was wondering if anyone had this code or could explain to me how to implement it.…
user3600355
  • 51
  • 1
  • 2
4
votes
1 answer

Sudoku timing irregularities

I wrote a Sudoku puzzle solver using brute force recursion. Now, I wanted to see how long it would take to solve 10 puzzles of similar types. So, I made a folder called easy and placed 10 "easy" puzzles in the folder. When I run the solver the first…
user1429254
  • 327
  • 1
  • 3
  • 10
4
votes
1 answer

Numpy: Truth comparison of multidimensional arrays

So I am writing a sudoku solver using a 9x9 array for the grid and a 9x9x9 array for its possibilities. Due to the backtracking algorithm I am using, I have to check whether the Sudoku is still valid, aka: If there is a field that does not contain a…
4
votes
3 answers

On Sudoku solving

Can someone please help me understand this solution: Initialize 2D array with 81 empty grids (nx = 9, ny = 9) Fill in some empty grid with the known values Make an original copy of the array Start from top left grid (nx = 0, ny = 0), check if…
Nasreddine
  • 36,610
  • 17
  • 75
  • 94
4
votes
1 answer

binary sudoku in swi prolog

As a prolog newbie, I wanted to try to implement a binary sudoku solver.(Code is below, swi-prolog). Binary sudoku is explained here : https://cstheory.stackexchange.com/questions/16982/how-hard-is-binary-sudoku-puzzle However, when performing the…
camel
  • 135
  • 5
4
votes
2 answers

Recursion: Backtracking sudoku solver in JS

I can't get this recursive algorithm working. It should solve a sudoku grid (a 2d array of ints). I've made the same in Java (but OOP of course) and it works fine. But in JS it doesn't. Values in the grid doesn't get changed and it never reaches the…
olefrank
  • 6,452
  • 14
  • 65
  • 90
4
votes
2 answers

sudoku check terms

I need to check if the number the user insert is already in the colum, row or "block" (still working on the last part). for some reason these checks don't work and I don't get why? I wrote the same code in the shell and it worked just fine. my…
user1816377
  • 235
  • 3
  • 6
  • 15
4
votes
2 answers

Sudoku recursive backtracking, unrecursing too early

So I am writing a sudoku solver in C++ and have run into a little snag. Below is my solve board code. It works for the first 3 rows of the puzzle, but unrecurses when hitting the end of the 4th row. Looking at the code on gdb it hits the end of the…
zberry92
  • 43
  • 4
4
votes
2 answers

Sudoku Board Using JPanels in Java

I know there have been several posts already about Sudoku-related questions, but I am not sure any of them have exactly what I am looking for... I am trying to build an empty Sudoku board in Java using JPanels and JTextfields. I also need to create…
Adam Daniel
  • 43
  • 1
  • 4
3
votes
3 answers

Generating random 'su doku' type matrices in MATLAB

I need to generate some 5x6 matrices in MATLAB. They need to consist of randomly generated integers in the range 1-6, however, an integer cannot occur more than once in a particular row or column. Here is the script I am currently using to generate…
AESmith
  • 33
  • 3
3
votes
2 answers

Sudoku recursion problematic while backtraking. (Brute Force)

Possible Duplicate: Sudoku solver in java, using backtracking and recursion I am creating a program that will solve a sudoku using recursion and brute force. My key problem is that I do not understand how I could concievably make it backtrack one…
Tony
  • 97
  • 2
  • 14