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
2 answers

How to make Sudoku solver with backtracking algorithm go back?

This weekend I worked on a Sudoku Solver (Ruby quiz) based on a backtracking algorithm. The sudoku is loaded in an array sudoku_arr of 81 integers (9x9 grid) where 0's are empty spots. There is a valid? method which checks if the sudoku_arr can be a…
user2609980
  • 10,264
  • 15
  • 74
  • 143
3
votes
1 answer

What's time complexity of this algorithm for solving Sudoku?

Sudoku Solver Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by the character '.'. You may assume that there will be only one unique solution. Personally I think, time complexity = O((n^2)!), n is…
Zhaonan
  • 939
  • 1
  • 11
  • 20
3
votes
1 answer

Sudoku Solver in CPLEX

I am trying to solve a Sudoku program that I created. This is the Objective Function IloNumExpr numExpr = cplex.linearNumExpr(); cplex.addMaximize(numExpr); What I am trying to do is to add to this either a constraint or new objective function that…
3
votes
7 answers

How do I fix this stack overflow error?

So I have what I think is pretty good code for a sudoku solver in java but I need some help with this method. It gives me a stack overflow when I embed it in a main method. The problem is that my method doesn't know how to turn around and fix its…
user233542
  • 31
  • 1
  • 1
  • 5
3
votes
1 answer

Sudoku recursion with backtracking

I am trying to solve any given sudoku puzzle using a recursive backtracking algorithm. I'm having two problems with my sudoku solver. First off, it solves for the puzzle, however it recurses back up and unsolves it in the process (solves in…
Adam Wechter
  • 41
  • 1
  • 1
  • 7
3
votes
2 answers

Java sudoku generator not working correctly

I have been working on a sudoku puzzle generator in java, I wrote this class to generate the puzzle but it is not correctly generating the puzzle. Here is an example of what I am getting: As you can see this is not a valid sudoku solution. But…
Petefic
  • 657
  • 6
  • 14
  • 31
3
votes
2 answers

Prolog Sudoku solver issue

I'm trying to write a sudoku 9 x 9 solver. I have used this following code: :-use_module(library(clpfd)). solve(X, Grid):- X = [A1, A2, A3, A4, A5, A6, A7, A8, A9, B1, B2, B3, B4, B5, B6, B7, B8, B9, C1, C2, C3, C4, C5, C6, C7, C8, C9, …
3
votes
0 answers

Maximum number of clues in a Sudoku game that does not produce a unique solution

You may have heard that last year it was proven that the smallest number of starting clues for a Sudoku game, guaranteeing a unique solution, is 17. An example is shown below. I am interested in the opposite: What is the largest number of starting…
Tom
  • 2,214
  • 2
  • 16
  • 28
3
votes
1 answer

Reaching JTextField in a DocumentListener

So, I finished making a Sudoku solver but I want to improve it. To do this I somehow need to reach my betterJTextField from the documentListener. I'm using a documentListener to read in real-time from my betterJTextFields, the problem I have is that…
Jakkra
  • 641
  • 8
  • 25
3
votes
2 answers

Removing cells from a Sudoku solution to make it a puzzle

I am writing a Sudoku application and am currently working on the game generation algorithm. I managed to figure out how to quickly generate a solution (not solve). I am stumped on how to remove some of the numbers to actually make it into a…
Tyler Crompton
  • 12,284
  • 14
  • 65
  • 94
3
votes
3 answers

How to recognise numbers in images using Netlogo programming sudoku

Hi everyone i have a problem of being able to identify numbers in an image using netlogo programming, Please any ideas or techniques on how to be able to identify numbers in a cell? I am making a sudoku game using netlogo coding. First i need to…
3
votes
1 answer

Java Sudoku solver throws divide by zero ArithmeticException

I am doing this Sudoku solver in java, and for some reason I have an error in my code that I just cant fix. My code has a guess function where it guesses numbers from 1-9 in each box while it checks if the number is already written before. The…
Ibrahim Yildirim
  • 2,731
  • 2
  • 19
  • 31
3
votes
1 answer

OpenCV - remove gridlines from Sudoku puzzle

I'm writing an Android app to extract a Sudoku puzzle from a picture. For each cell in the 9x9 Sudoku grid, I need to determine whether it contains one of the digits 1 through 9 or is blank. Here are the broad strokes of my algorithm: Adaptive…
1''
  • 26,823
  • 32
  • 143
  • 200
3
votes
4 answers

Filling a 2D array with randomised numbers

I have started a project trying to create a Ken Ken puzzle. If you are not sure what Ken Ken is, it is similar to Sudoku in the way that there can be no duplicated integer values in a row or column. I am trying to fill a 2D Array with numbers from…
Jordan King
  • 93
  • 1
  • 6
3
votes
1 answer

Sudoku Solver debugging

I know that there are a few posts like these before, but they aren't helping me. I am writing a program that can solve a sudoku. I found an algorithm here: http://www.heimetli.ch/ffh/simplifiedsudoku.html . I am trying to write it in java and…
Sean Lev
  • 121
  • 1
  • 6