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

Sudoku elimination strategy

Suppose I have Sudoku array which is used in Sudoku solver such as: [[0 0 0 0 0 0 0 5 0] [2 0 7 0 0 9 0 0 0] [6 0 0 3 5 1 0 0 0] [5 0 0 0 0 0 0 1 0] [0 0 3 0 0 0 0 0 8] [0 0 0 8 2 0 5 3 0] [0 0 0 0 7 0 8 0 4] [0 0 6 2 0 0 0 0 0] [0 8 0 0 0 0…
3
votes
0 answers

My sudoku backtrack algorithm isn't working after the 7th line. What am I doing wrong?

My code runs but when I try to print the board using a function and when I check if the algorithm had aleast solved the board, it only solves up to the 7th line then stops. In my process to see what I was doing wrong I printed my board right after…
3
votes
2 answers

prolog sudoku block algorithm?

how to get all elements of the blocks in prolog? the size can change dynamic in my code, so the blocksize differs, 4x4 = 4 elements, 9x9= 9 elements etc. the blocks are cut into squares, so in 4x4 the horizontal length is round(sqrt(4))= 2 and…
viktor
  • 31
  • 2
3
votes
1 answer

How to generate a list of all distinct 3x3 Latin Square in Python

Latin Square is an nxn array filled with n different symbols, each occurring exactly once in each row and exactly once in each column (like sudoku). An example of Latin Square: 1 2 3 2 3 1 3 1 2 This is what I've tried, but it is still not all…
Vince
  • 33
  • 2
  • 5
3
votes
5 answers

Simple Sudoku solving method

Note: this problem has been solved, the actual problem is NOT in this method but the other, so if you're searching for something about Sudoku and finally get into this page, you can absolutely use my method below, it works. Ok, forget…
user743234
3
votes
1 answer

How Backtracking works in Python

I come up with this piece of code learning from Youtube. I use this to solve Sudoku by performing Backtracking. import pandas as pd import numpy as np raw = pd.read_csv(r'C:\Users\Administrator\Dropbox\Python_Learning\debaisudoku.csv', header =…
Appscript.me
  • 45
  • 1
  • 6
3
votes
1 answer

Pulp Killer sudoku - check choices are distinct for choice of variables

I am trying to solve killer Sudoku using Python linear optimization library, Pulp. https://en.wikipedia.org/wiki/Killer_sudoku Here is my attempt so far, adding a constraint that each row must add up to 45. import pulp prob = pulp.LpProblem("Sudoku…
oli5679
  • 1,709
  • 1
  • 22
  • 34
3
votes
1 answer

How to output list of valid numbers at a certain space?(for Sudoku)

This is what I have. The method should output an array of all available numbers in that space. For some reason, this doesn't filter out for the same box/row/col. How should it be coded properly? public int[] getAllowedValues(int row, int…
user10102227
3
votes
1 answer

Sudoku - Loop scanner

I'm currently making a Sudoku using java, however i can't seem to figure out how to loop my scanner properly. So far it prints this: . 1 . | 3 . . | 8 . . 5 . 9 | 6 . . | 7 . . 7 . 4 | . 9 5 | . 2 . ---------------------- 4 . . | . . . | 1 . . .…
Stylo
  • 67
  • 5
3
votes
1 answer

Preprocessing methods for OCR on low quality digit images?

I'm currently working on a project that will read in an image of a Sudoku grid, detect the grid, identify the digits, solve the puzzle, & overlay the solution on the image. In order to identify the digits, I've divided the grid into n*2 images,…
sansona
  • 31
  • 2
3
votes
1 answer

Recursive backtracking Algorithm in JavaScript

I am currently trying to learn about backtracking Algorithms and have been working on a Sudoku game. I understand the basic working of the algorithm and have written a Sudoku solver using it. My current problem is related to removing a set amount of…
3
votes
1 answer

Outputting a list of lists in Haskell?

I am a complete beginner to Haskell but I'm being asked to create a sudoku solver. I've been making some steady progress with it but one of the things it is asking me to do is print a valid representation of a sudoku puzzle s. The Puzzle data type…
sea1997
  • 43
  • 6
3
votes
1 answer

how to set values in a list in prolog for the sudoku game

I have these code: :- use_rendering(sudoku). :- use_module(library(clpfd)). sudoku(Rows) :- length(Rows, 9), maplist(same_length(Rows), Rows), append(Rows, Vs), Vs ins 1..9, maplist(all_distinct, Rows), transpose(Rows, Columns), …
john
  • 117
  • 4
3
votes
1 answer

Javascript Uncaught TypeError: Cannot read property 'getElementsByTagName' of null

I'm trying to code a Sudoku generator in JavaScript and I think I did it. My problem is for visualizing the generated solution inside the input tags I use for the game. I put this function on the property onload of the body of my html…
TheDini
  • 27
  • 1
  • 8
3
votes
4 answers

neural network for sudoku solver

I recently started learning neural networks, and I thought that creating a sudoku solver would be a nice application for NN. I started learning them with backward propagation neural network, but later I figured that there are tens of neural…
Andrey
  • 61
  • 1
  • 6