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
13
votes
4 answers

How to re-use a thread in Java?

I am a building a console Sudoku Solver where the main objective is raw speed. I now have a ManagerThread that starts WorkerThreads to compute the neibhbors of each cell. So one WorkerThread is started for each cell right now. How can I re-use an…
David
  • 1,842
  • 2
  • 21
  • 31
11
votes
2 answers

Logic Solving Algorithm (for Sudoku in Java)

I'm having issues with my logic solving algorithm. It solves puzzles with a large number of hints very well, it just has issues with puzzles that have less than 45 clues. This is the algorithm for solving. Immutable is a boolean that determines…
SkylineAddict
  • 189
  • 1
  • 2
  • 13
11
votes
2 answers

Algorithm Complexity (Big-O) of sudoku solver

I'm look for the "how do you find it" because I have no idea how to approach finding the algorithm complexity of my program. I wrote a sudoku solver using java, without efficiency in mind (I wanted to try to make it work recursively, which i…
Eric Muller
  • 159
  • 1
  • 1
  • 6
10
votes
4 answers

Sudoku generator algorithm

I made an algorithm to generate sudokus, but it was terribly inefficient. Each puzzle took minutes to generate. So now I am trying to write it again in optimal way. But I am experiencing some problems I need help with. There are two…
user1018711
10
votes
6 answers

Sudoku backtracking algorithm

First of all, I'll state that this is a university assignment so I'm not asking for someone to write the code for me I just need to be pointed in the right direction. :) Ok, so I need to write an algorithm to solve any (solvable) sudoku board of…
JimR
  • 2,145
  • 8
  • 28
  • 37
9
votes
2 answers

Sudoku Puzzle with boxes containing square numbers

Two days ago, I was given a sudoku problem that I tried to solve with Python 3. I've been informed that a solution does exist, but I'm not certain if there exists multiple solutions. The problem is as following: A 9x9 grid of sudoku is completely…
balways
  • 101
  • 5
9
votes
2 answers

Sudoku solving algorithm with back-tracking

I'm looking to implement a very simple algorithm that uses brute-force back-tracking to solve Sudoku grids. The problem I'm facing is that in my implementation I included two instance variables for a Sudoku class called row and col, which correspond…
Macalaca
  • 125
  • 2
  • 8
9
votes
2 answers

Solving Sudoku using a genetic algorithm

I've taken on the task of creating a sudoku solver using a genetic algorithm. Initialization: Store the given values in each chromosome, and then randomly generate values such that each row is a valid permutation of the values 1 through 9. Fitness:…
Ryan
  • 3,127
  • 6
  • 32
  • 48
9
votes
4 answers

Generating a sudoku of a desired difficulty?

So, I've done a fair bit of reading into generation of a Sudoku puzzle. From what I can tell, the standard way to have a Sudoku puzzle of a desired difficulty is to generate a puzzle, and then grade it afterwards, and repeat until you have one of an…
ZachLHelms
  • 317
  • 1
  • 4
  • 10
8
votes
1 answer

Determine if Sudoku is solvable in JavaScript

This is a problem from Pramp. I need to determine if a sudoku is solvable or not (not like LEETcode question where I just need to see if a board is valid or not). Below is my code in JavaScript, using recursion. I'm following the logic suggested on…
V. Wang
  • 151
  • 6
8
votes
7 answers

Sudoku solver in JS

I'm trying to write an algorithm that can solve sudoku. For now, my code works till supplyGrid is out of numbers. When it happens it should go back and try another number, right? To be honest I have no clue how to achive that. var grid = [ …
Xaoo
  • 167
  • 1
  • 3
  • 9
8
votes
2 answers

I don't understand what label does in Prolog

I went through the manual and documentation but still don't understand. I'm trying to implement a sudoku solution where after writing out all the other rules of the game, I've added label(Board) according to my teacher's instructions. However I…
NewGuy
  • 89
  • 1
  • 5
8
votes
6 answers

How to Generate a -complete- sudoku board? algorithm error

I'm trying to generate a complete (ie, each cell filled with a number) Sudoku-like board. It's for something else that has nothing to do with sudokus, so I am not interested in reaching a sudoku with white squares that can be solved, or anything…
Adelaiglesia
  • 365
  • 1
  • 4
  • 16
8
votes
2 answers

Unique methods to generate sudoku puzzle

How many possible unique ways are there to generate a Sudoku Puzzle?? I can think of only two possible ways 1) Take a solved Sudoku puzzle and shuffle the rows and columns 2) Generate a random number and check if it violates any Sudoku constraints,…
Computernerd
  • 7,378
  • 18
  • 66
  • 95
7
votes
6 answers

Recursive solution to Sudoku generator

I'm trying to code an algorithm that creates a legal Sudoku board in either Java or Javascript. Neither work, and I'm not entirely sure why. Essentially, the problem in both programs is that either x or y is getting incremented more than it should…
SomeKittens
  • 38,868
  • 19
  • 114
  • 143
1
2
3
79 80