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

How to detect Sudoku grid board in OpenCV

I'm working on a personal project using opencv in python. Want to detect a sudoku grid. The original image is: So far I have created this: Then tried to select a big blob. Result may be similar to this: I got a black image as result: The code…
Gabriel Muñumel
  • 1,876
  • 6
  • 34
  • 57
7
votes
3 answers

Sudoku - Find Current Square Based on Row,Column

Based on the above coordinates in the above image, I'd like to be able to calculate which "square" as highlighted in red, the selected cell belongs to. I'm solving a sudoku puzzle, and I have access to the width of each square, as well as the…
ILoveToCode
  • 73
  • 1
  • 3
7
votes
4 answers

Proper data structure to represent a Sudoku puzzle?

What would be a smart data structure to use to represent a Sudoku puzzle? I.e. a 9X9 square where each "cell" contains either a number or a blank. Special considerations include: Ability to compare across row, column, and in 3X3 "group Ease of…
Rafe Kettler
  • 75,757
  • 21
  • 156
  • 151
7
votes
4 answers

Building an EFFICIENT Sudoku Solver

Yes, I know this is nothing new and there are many questions already out there (it even has its own tag), but I'd like to create a Sudoku Solver in Java solely for the purpose of training myself to write code that is more efficient. Probably the…
Justian Meyer
  • 3,623
  • 9
  • 35
  • 53
7
votes
2 answers

Determine whether a Sudoku has a unique solution

I'm struggling with a backtracking algorithm to determine wether a Sudoku has a unique solution or if it has multiple Solutions. Here's the backtracking code i use: static boolean solve(int i, int j, int[][] cells) { if (i == 9) { i…
user4758246
  • 575
  • 5
  • 13
7
votes
14 answers

Sudoku Checker in Python

I am trying to create a sudoku checker in python: ill_formed = [[5,3,4,6,7,8,9,1,2], [6,7,2,1,9,5,3,4,8], [1,9,8,3,4,2,5,6,7], [8,5,9,7,6,1,4,2,3], [4,2,6,8,5,3,7,9], # <--- …
quagpwn
  • 71
  • 1
  • 1
  • 4
7
votes
1 answer

Sudoku solve method

I've a problem with my sudoku solving method. The program works like this; the board is empty when started, the users adds a couple of numbers to the board and then by hitting a Solve-button the program tries to solve it. Everything works fine…
Rob
  • 315
  • 4
  • 15
7
votes
2 answers

Generating minimal/irreducible Sudokus

A Sudoku puzzle is minimal (also called irreducible) if it has a unique solution, but removing any digit would yield a puzzle with multiple solutions. In other words, every digit is necessary to determine the solution. I have a basic algorithm to…
1''
  • 26,823
  • 32
  • 143
  • 200
6
votes
2 answers

sudoku solver using backtracking

I've recently been working on a backtracking sudoku solving algorithm and currently I'd like to ask on how I should go about to change my solve() method from void to a boolean. I'm using a very simple backtracking algorithm, and it's currently…
zak.oud
  • 152
  • 1
  • 2
  • 6
6
votes
4 answers

Java Sudoku Generator(easiest solution)

In my last question seen here: Sudoku - Region testing I asked how to check the 3x3 regions and someone was able to give me a satisfactory answer (although it involved a LOT of tinkering to get it working how I wanted to, since they didn't mention…
HunderingThooves
  • 962
  • 8
  • 20
  • 33
6
votes
3 answers

Trying to solve Sudoku with cvxpy

I'm trying to solve a Sudoku with cvxpy optimization package. I'm really new to both optimization and cvxpy. The constraints are: all the values are between 1 to 9 sum of all rows = 45 sum of all columns = 45 sum of all squares = 45 the given…
Binyamin Even
  • 3,318
  • 1
  • 18
  • 45
6
votes
3 answers

Sudoku Solver Program

solveSudoku function is called from main() function. I have written the following function for solving sudoku : #include #include using namespace std; int isvalid(char k, vector > A, int i, int j) { //Checking if…
Gyanshu
  • 189
  • 15
6
votes
1 answer

Solving Naked Triples in Sudoku

I wished I paid more attention to the math classes back in Uni. :) How do I implement this math formula for naked triples? Naked Triples Take three cells C = {c1, c2, c3} that share a unit U. Take three numbers N = {n1, n2, n3}. If each cell in C…
Houman
  • 64,245
  • 87
  • 278
  • 460
6
votes
3 answers

Need to skip newline char (\n) from input file

I am reading in a file into an array. It is reading each char, the problem arises in that it also reads a newline in the text file. This is a sudoku board, here is my code for reading in the char: bool loadBoard(Square…
codefail
  • 371
  • 1
  • 8
  • 20
6
votes
2 answers

Sudoku solver bug

I don't know what I'm doing wrong, and I've been staring at this code all day. This is a "standard" Sudoku solver in Java, that takes a int[][] with 0's where the empty spaces are. Given I'm only passing in a board with 35 holes, this should be…
SomeKittens
  • 38,868
  • 19
  • 114
  • 143
1 2
3
79 80