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
-1
votes
1 answer

Sudoku generator interactions pane error

For a project we have to code a program that generates a sudoku board and allows us to complete it as well. I have coded most of the project and I feel like I have nailed it from a logical standpoint but I can't find the coding errors that appear in…
-1
votes
3 answers

Problems with backtracking Sudoku Solver [Java]

Problem: Writing a backtracking sudoku solver in Java that takes in a file representing the puzzle, converts it into a matrix, and using recursive backtracking, solves it. Issue: In my solve method, it will try to solve the first empty box however…
Adam Wechter
  • 41
  • 1
  • 1
  • 7
-1
votes
1 answer

Sudoku solving matrix, while statement gives an infinite loop

This code should produce a solved sudoku matrix, however the while statement puts it in an infinite loop. Removing the while statement gives me a matrix with some values still 99 or 0. And i can't generate 9 random numbers uniquely one by one. IF…
-1
votes
1 answer

Nested loops and python programming for sudoku puzzle

What code can I write for nested loops to print the row, column and number for each non-empty location in bd. bd = [ [ '1', '.', '.', '.', '2', '.', '.', '3', '7'], [ '.', '6', '.', '.', '.', '5', '1', '4', '.'], [ '.', '5', '.', '.',…
-1
votes
2 answers

What is wrong with my backtracking algorithm?

I am working on a program that generates sudoku puzzles. I was trying to use a backtracking algorithm to do this but my program is not working. The program just runs infinitely and never returns a solution. I don't know if its just a minor problem…
Petefic
  • 657
  • 6
  • 14
  • 31
-1
votes
1 answer

Distributing numbers in SuDoku

I am creating a SuDuko Generator, and am trying to distribute my 1's to every single box. To do this, I have created a list with two items (acting a coordinates). After the function has run, it returns a list such as [a, 1]. I then want a quick way…
user2120617
-1
votes
2 answers

Python, OpenCV and Sudokus

With the PDF below, I would like to do the following things. Localize the four sudoku grids so as to treat each of them separately. For each grid picture, I would like to obtain a matrix of the pictures corresponding to each cell. Finally, I would…
user1054158
-2
votes
2 answers

Write an application that determines whether a Sudoku square is valid

Write an application that determines whether a Sudoku square is valid. The code works well now. Example: For input data: 9 1 8 5 7 2 6 4 3 7 5 3 6 9 4 1 8 2 2 6 4 1 8 3 7 9 5 1 9 6 4 2 8 5 3 7 3 8 2 7 5 6 9 1 4 5 4 7 9 3 1 8 2 6 4 7 9 …
user17693898
-2
votes
3 answers

Sudoku with user input

I am trying to write a Sudoku game with user input. So the user can choose what row/column it wants to and what number. I have to import it from a text file and have made a save and load function. I have tried starting with what I know, but I don't…
-2
votes
1 answer

Displaying sudoku program in python

I have to update a nested list sudoku with grids and borders. My output is not printing as intended and I am not sure how to fix it. This is my code with the test input cases and intended output vs output right now. The code below has the…
user16812303
-2
votes
1 answer

Sudoku Solver gives Partial Solution in Python: Why?

I was trying to solve the leetcode Sudoku Solver Problem (Problem description here). But my code is only giving partial solution. class Solution(object): def solveSudoku(self, board): """ :type board: List[List[str]] …
Mousumi
  • 33
  • 6
-2
votes
1 answer

Draw samurai sudoku grid on WPF

I want to draw a samurai sudoku grid on my C# WPF project. this is the example of samurai sudoku for each TextBox within the grid, I want to load it with dynamic value from the txt file. txt file : "23987239847239847" (in total 405 integers) I…
-2
votes
2 answers

Why does this function print the result, but return none?

def solve(sudoku): for y in range(9): for x in range(9): if sudoku[y][x] == 0: for n in range(1, 10): if possible(x, y, n): sudoku[y][x] = n …
Henri
  • 61
  • 1
  • 3
-2
votes
2 answers

How to check if sudoku is valid or not

I have written a java program to check if sudoku solution is valid or not, but its not working, It's giving false for all values, the program logic is correct according to me. I want to do this without hashsets, and in the simnplest way, hence I…
IIT Topper
  • 39
  • 7
-2
votes
1 answer

Stuckked in sudoku solving program.. unable to find out my mistakes

https://github.com/Malaya2184/PY100/blob/master/sudoku/sudoku.ipynb need solution to my program i.e 9*9 sudoku solving prohram in python