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

Sudoku solver not working

I am trying to create a sudoku solver by first calculating the possible values that can be put in the square. Then using these constraints to backtrack using System; using System.Collections.Generic; using System.Linq; using System.Text; using…
RStyle
  • 875
  • 2
  • 10
  • 29
-3
votes
1 answer

Iterative brute-force sudoku solver

I am trying to implement an iterative Sudoku solver. To avoid recursion I used a stack, but I'm having problems with its management. The starting board is represented by a String array (variable 'input' in the following code) in which each element…
Emonale
  • 513
  • 2
  • 7
  • 22
-3
votes
1 answer

Java: Complete Sudoku Generator, what I am missing here?

I'm working on sudoku project and I found this: http://www.codeproject.com/Articles/23206/Sudoku-Algorithm-Generates-a-Valid-Sudoku-in I converted that code into java but I just can't see where I have made mistake... It almost works but it still…
plexcell
  • 1,647
  • 2
  • 15
  • 29
-3
votes
2 answers

Making a sudoku on java

I'm a new programmer. After making some programs through my self learning in java, now I'm interested to make a sudoku in that language. Can anyone explain me how to control the 9x9 grids and randomising the numbers each time the program runs?…
Subhranil
  • 851
  • 1
  • 8
  • 23
-3
votes
1 answer

Sudoku 3x3 box check if duplicate in C

I have found a function on internet here for solving my problem on Sudoku written in C language.I have almost everything done but I am stuck here, I can't check the 3x3 box if any value is duplicated: /** * Check if a value contains in its 3x3 box…
Marian Pavel
  • 31
  • 2
  • 6
-3
votes
1 answer

Sudoku generator: ArrayOutOfBoundsException

In this project, I am trying to write a program that creates a 9x9 Sudoku board with 9 3x3 subgrids, along with a header row and column that lists the letters a to i. The program compiles correctly, but when I hit run, it gives the following…
-3
votes
1 answer

Sudoku in C vs Sudoku in Java

I recently wrote a simple straightforward C code that solves Sudoku and that uses recursion and backtracking. You will find below the code that I just described. Everything works fine. #include # define INsigned 0 int grid[9][9]; void…
Mes M
  • 17
  • 2
-3
votes
1 answer

How do I update my columns value in my 2 dimensional array in java?

Building a Sudoku game. How can I update my 2 dimensional array with the users input if they decide to input data using columns and not rows? I can not figure out why it will not work properly? else if (dataSelection == 2) { if…
Brandon
  • 933
  • 1
  • 10
  • 19
-3
votes
1 answer

C# sudoku solver Variable malfunction

The problem here is, that emptyRow and emptyCol variables somehow do not tend to work and are always equal 0, even when I actually assign them values at initialization! As well, do you see any mistakes that I could have made here? Here's the…
-3
votes
1 answer

Simple sudoku puzzle solver python

I'm trying to write a simple sudoku solver in python. The basic concept is that the sudoku puzzle is partially filled in and the unsolved cells are indicated by zeros. Any cell denoted by a zero can be solved at any stage of the puzzle. So if the…
-4
votes
1 answer

Showing step by step solving of sudoku

Is there any way to show the steps of solving a sudoku? My code just solve it within 0.5 second and I wish to modify it to show the changes on the sudoku grid step by step on processing. (I am using python)
Christopher
  • 142
  • 7
-4
votes
1 answer

How do I verify if the sudokus lines do have all 9 digits?

Could someone please give me advice of how to start my code? I am supposed to verify if a text document containing rows of 9 numbers do have all 9 digits. If so, my code should say True, otherwise False. Here is one of the text document…
Michelle
  • 1
  • 4
-4
votes
1 answer

How to convert a 2d array to a sudoku image in svg or png format?

I am trying to make a sudoku generator in C++, for which I have the resulting puzzle stored as a 2D matrix. How can I generate an svg image or png image of that array like a sudoku? Like I know I can use many tools like svg++, Qt, simple-svg, and…
-4
votes
1 answer

Backtracking - Generate Sudokuarray

i want to generate a simple Sudokugenerator using backtrack. I am stuck / don't know if i used backtracking properly. zahlIstGueltigAufPosition returns if the number zahl is valid (if zahl appears once in the row/column or one of the 9 Boxes).…
MisterMushn
  • 71
  • 2
  • 10
-4
votes
2 answers

Setting int[index] = matrix[index][otherindex]

int[] array = new int[9]; int[][] matrix = { {0,1,2}, {3,4,5}, {6,7,8}}; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { array[i+j] = matrix[i][i]; …