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

Python Sudoku Recursion with Brute Force Backtracking Error

I am doing a Sudoku puzzle solver for homework, but am encountering some difficulty. The code right now cycles past the solution, although it does reach it for easy puzzles, and for harder puzzles, it gets stuck with several 9's for no apparent…
4
votes
3 answers

C# alternative to lock if volatile isn't a good idea

I'm sorry I know this topic has been done to death (I've read I've read this and this and a few more) but there is one issue I have which I am not sure how to do 'correctly'. Currently my code for a multithreaded Sudoku strategy is the…
SmallJoeMan
  • 353
  • 4
  • 9
4
votes
2 answers

C++: sudoku (copy board)

I'm new to c++ and got a problem when doing homework (sudoku). Instruction said: "you have to create a new board being a copy of the current board (use the copy constructor and allocate the board from the heap with new)." I've tried (it's wriiten…
Ferry
  • 583
  • 8
  • 18
4
votes
1 answer

What's wrong with my sudoku solver function?

ok so i changed my function to a backtracking function (which i found online). It still reads from a file and inputs it in an array, the check function is working properly so i haven't changed that. If your wondering the following is the puzzle I'm…
4
votes
1 answer

Need help with backtracking algorithm for generating Sudoku board

I have written an algorithm for generating a Sudoku board but it is failing. I have written it based on this though it does differ as I had written a lot of my code before I stumbled upon this. The Code I have a multidimensional array set up for…
punkrockbuddyholly
  • 9,675
  • 7
  • 36
  • 69
4
votes
5 answers

Python Recursive Sudoku Solver Doesn't Return the Solution

I tried to optimize this code and my final code was as shown below import numpy as np sudoku = np.array([[0, 9, 0, 0, 5, 0, 6, 0, 8], [0, 0, 0, 7, 1, 0, 3, 5, 0], [2, 1, 0, 0, 0, 0, 7, 0, 4], …
gokdumano
  • 70
  • 6
4
votes
1 answer

prolog fill a list automatically with variables in loop

how to fill a list automatically with variables? like for(i=1;i<=9,i++){ addtoanylist(X_i); } so that the result is like L=[X1,X2,X3,X4,X5,X6,X7,X8,X9]. ? its because i want to build up a proper size of a list for my sudokusolver. i get the…
viktor
  • 51
  • 3
4
votes
3 answers

Sudoku Backtracking with Solution Counter

Background I've implemented a sudoku-solver algorithm (backtracking) that looks like this: //Backtracking-Algorithm public static boolean solver(int[][] board) { for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { if…
user13634030
4
votes
2 answers

Mini sudoku solver in Prolog stops partway through

I'm working through 'Seven Languages in Seven Weeks', and I'm just trying to get an example from the book working. It solves a mini sudoku grid (4x4). The author is using gprolog, but I am using swi-prolog (I couldn't get gprolog to work on my VM…
Nick Knowlson
  • 7,185
  • 6
  • 47
  • 63
4
votes
5 answers

Fill a Matrix with Random Number with no repeat vertically or horizontally

This is more of a logical question . Problem IS: I need to fill a Matrix with number (1-9) In such a way so that : No number should repeat in row No number should repeat in column Matrix can be from 3X3 to 8X8 Matrix should contain Random numbers…
ADM
  • 20,406
  • 11
  • 52
  • 83
4
votes
1 answer

Using a giant hashtable to solve a sudoku in polynomial time

Say you were to create a hash table that maps every possible valid 9x9 sudoku (not yet filled in) to its solution. (as infeasible a task as this would be) Then you were to create a simple program that takes a valid 9x9 sudoku (again, not yet filled…
svaerth
  • 61
  • 1
  • 5
4
votes
1 answer

Prolog solve Sudoku

I'm rather new at Prolog and found this example on swi-prolog.org to solve a sudoku. But I can't run it. I looked up same_length and there is only same_length/2 not same_length/1. Also all_distinct/2 and not all_distinct/0.…
4
votes
3 answers

Brute force sudoku solver algorithm in Java problem

Everything seems to work fine in the algorithm besides the solve method. When it executes the program using a solvable Sudoku board, it says that it cannot be solved. I've tried everything I can think of in the solve method. I've tried debugging and…
jesse
  • 117
  • 2
  • 8
4
votes
3 answers

identify programming language

Please identify this programming language: *Main> [ ((a,b,c),(d,e)) | a <- [1..7], b <- [2..8], c <- [3..9], d <- [1..8], e <- [2..9], a < b, b < c, d < e, List.intersect [d,e] [a,b,c] == [], a+b+c…
Handcraftsman
  • 6,863
  • 2
  • 40
  • 33
4
votes
3 answers

How to print 2D Arrays to look like a grid/matrix?

I'm trying to print Sudoku like grids. The desire output would be: int [][] easyGrid = {{2, 3, 5, 9, 7, 1, 8, 4, 6}, {4, 7, 1, 2, 8, 6, 9, 3, 5}, {8, 9, 6, 4, 3, 5, 2, 7,…
user45678
  • 343
  • 2
  • 6
  • 19