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
5
votes
3 answers

Sudoku GUI using java

I'm currently working on my GUI for this Sudoku solver I'm making. I've managed to print out the board with no problems. However I'd like to know how I would go about to differentiate the 3x3 regions with some kind of thicker or coloured…
zak.oud
  • 152
  • 1
  • 2
  • 6
5
votes
3 answers

Astar-like algorithm with unknown endstate

A-star is used to find the shortest path between a startnode and an endnode in a graph. What algorithm is used to solve something were the target state isn't specifically known and we instead only have a criteria for the target state? For example,…
Mizipzor
  • 51,151
  • 22
  • 97
  • 138
5
votes
9 answers

Sudoku algorithm in C#

I need one liner (or close to it) that verifies that given array of 9 elements doesn't contain repeating numbers 1,2,3,...,9. Repeating zeroes do not count (they represent empty cells). The best I have came out so far is: var a = new int[9]…
Prankster
  • 4,031
  • 5
  • 33
  • 44
5
votes
11 answers

Check if Sudoku solution is valid

You're given a solution to a Sudoku puzzle. Write the code to check if it's a valid solution. Your function signature should be: boolean isValid(int starti, int startj, int endi, int endj) Rules for those unfamiliar with Sudoku: Grid size is 9x9,…
Sarp Centel
  • 1,283
  • 2
  • 14
  • 23
5
votes
2 answers

What is a time complexity for Algorithm X for sudoku?

I've found here a statement that Algorithm X for sudoku has O(N^3) time complexity where N is a board size. That's maybe logical, since for sudoku the binary matrix to compute has N^3 rows. But that makes sudoku problem solvable in a polynomial…
tkrishtop
  • 734
  • 1
  • 8
  • 18
5
votes
2 answers

Is SUDOKU np-complete?

I did go through this. I don't understand this. Sudoku is NP-complete when generalized to a n × n grid however a standard 9 × 9 Sudoku is not NP- complete.
Akhil
  • 369
  • 1
  • 5
  • 13
5
votes
6 answers

How to show a sodoku solution is unique

Given a unsolved sodoku, how can one show that it has a unique solution?
ericg
  • 8,413
  • 9
  • 43
  • 77
5
votes
1 answer

Stuck in Sudoku backtracking solver (Java)

I have been trying to figure out my mistake in the Sudoku backtracking solver for three days. The problem is from leetcode Sudoku Solver. My solver is based on the deduction in the attached picture. The problem is that my board is changed even if a…
Appalachian Math
  • 169
  • 1
  • 10
5
votes
2 answers

Viewpoints Sudoku

I'm looking for alternative viewpoints to solve sudoku problems using constraint programming. The classical viewpoint is to use a finite domain (row, column) variables who can take values from 1 to 9. This is a good viewpoint and it's easy to define…
Stanko
  • 4,275
  • 3
  • 23
  • 51
5
votes
3 answers

Brute force Algorithm for creation of Sudoku Board

What I am developing is that initially the entire sudoku board is empty. One of the random cells(out of 81) is filled with a random value(1-9). Now I want to fill all the remaining cells using brute force approach. From what I came to know after…
Akshay J
  • 5,362
  • 13
  • 68
  • 105
5
votes
2 answers

Multi-Sudoku AI approach

I'm conceptualizing a solver for a variant of sudoku called multi-sudoku, where multiple boards overlap like so: If I understand the game correctly, you must solve each grid in such a way that the overlap between any two or more grids is part of…
5
votes
1 answer

Problem porting sudoku solver from C to Python

I recently wrote a sudoku solver in C to practice programming. After completing it I decided to write an equivalent program in Python for a comparison between the languages and more practice and this is where the problem is. It seems to be that a…
5
votes
2 answers

How to prevent genetic algorithm from converging on local minima?

I am trying to build a 4 x 4 sudoku solver by using the genetic algorithm. I have some issues with values converging to local minima. I am using a ranked approach and removing the bottom two ranked answer possibilities and replacing them with a…
Marcus Koz
  • 255
  • 5
  • 21
5
votes
3 answers

Code explanation of Sudoku Solver

I have question about the following code snippet: It is a sudoku solver which solves a Sudoku puzzle by filling the empty cells. I can not really get the logic behind the solver method. Why does it return false after trying k=1-9 and return true…
shirley
  • 1,640
  • 4
  • 12
  • 19
5
votes
4 answers

Sudoku algorithm with backtracking - java

So I have this university assignment to solve Sudoku... I read about Algorithm X and Dancing algorithm, but they didn't help me. I need to make it with backtracking. I hard-coded some of the indexes in the two dimensional array with numbers on…
Milkncookiez
  • 6,817
  • 10
  • 57
  • 96