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

I don't understand why my Java program doesn't run

import java.util.Scanner; public class Sudoku { public static void main(String[] args) { int[][] grid = readAPuzzle(); if (!isValid(grid)) System.out.println("Invalid Input"); else if (search(grid)) { …
-4
votes
1 answer

Python: function returns a list even though it shouldn't

I made a program that solves 4x4 sudoku using backtracking algorithm (the grid is split into 2 parts which are also split into 2 parts with 4 cells) , it has 3 functions, first prints the grid, second checks if a number can be placed into a cell,…
Lunix
  • 1
  • 1
-4
votes
2 answers

Sudoku: Show int value as whitespace

I'm a newbie to java programming and created a console-based Sudoku Game as practice. A backtracking algorithm generates a completed Sudoku and another method 'digs holes' into random cells (regarding the difficulty). Right now, the value 0 is set…
Clemensius
  • 43
  • 1
  • 5
-4
votes
1 answer

java sudoku why it doesnt show me the final result of sudoku

good evening, i tried to create an application who generate an initial sudoku and trying to complete it using A* algorithm, while executing, the initial state it shows, but when it starts to solve, the program closes without showing a result,…
-4
votes
1 answer

Why does my program crash with a stack overflow?

My program works fine when i use a 81 elements array but when i deal with a 256 blocks array it crashes and i dont know why it does that. I present to you the all source code and in the input text that you can use in a .txt file with a last carriage…
-4
votes
1 answer

Sudoku generator causes random endless loop [C]

I'm making a sudoku generator in C, but when I start the program it goes random in endless loop. Sometimes it prints all the rows, sometimes only one, etc.. etc.. (See images below) This is the code What is the problem? #include #include…
Leonardo
  • 499
  • 1
  • 7
  • 18
-4
votes
1 answer

Diagonal Sudoku

I implemented a diagonal sudoku. Diagonals must not have repetitions My algorithm to check the diagonal was. copy diagonals to arrays left_x and right_x for(i) for(j) if(left_x[i]==left_x[j]&&i!=j) return false for(i) for(j)…
CrazyGirl
  • 35
  • 7
-4
votes
1 answer

I am trying to run this sudoku solver and a weird error appears

My objective is to solve a sudoku game while using a backtracking algorithm. When I run it I get this error message: obj/sudoku_solver.o: In function sudoku_backtracker(std::__1::vector >,…
-4
votes
2 answers

Sudoku solver, not backtracking solver

The past few weeks I've been working on a sudoku game. The game as a lot of features such as: play game, print sudoku, solve sudoku. The solve function uses conventional backtracking but thats not the issue, the issue is that I need the game to be…
Simon Jensen
  • 488
  • 1
  • 3
  • 19
-4
votes
1 answer

Genetic Algorithm for Sudoku

can anyone please teach me how to use Genetic Algorithm to solve the sudoku generated by the source code below? The newly created Genetic Algorithm solver for the sudoku should use back the instances in the source code below. import…
Alan
  • 1
  • 1
  • 3
-4
votes
1 answer

Java Sudoku: Generic Array Creation

Possible Duplicate: Java how to: Generic Array creation Generic array creation error private ArrayList[][] potentialList = new ArrayList[9][9]; Someone, please explain to me why this statement gives me a: …
-5
votes
1 answer

Java: how do you run this program?

I'm new to programming and am trying to teach myself. I found this Sudoku solving algorithm online but I can't seem to run it - I think I have to create a main method but I don't know what parameters to put inside it and how to call other…
Mimi
  • 21
  • 3
-5
votes
4 answers

c program to check valid sudoku

i'm writing c code to check whether given matrix is valid sudoku solution or not. Input would be matrix of n*n size. I have written code to check row and column but i'm not getting how to validate grids of sqrt(n)*sqrt(n) size. my code is…
amit
  • 1
  • 1
  • 2
  • 4
-5
votes
1 answer

C# Read int numbers to array

using System; using System.IO; namespace Sudoku { class Game { private int[,] puzzle = new int[9, 9]; public void saveToFile() { StreamWriter str = new StreamWriter("SUDOKU.txt"); for (int i…
-6
votes
1 answer

Create int array from txt file with multilines and spaces between numbers in C

I have a sudoku checker. I need to catch numbers of the sudoku.txt into an array of ints in C. My sudoku.txt is multi lined and the numbers are separated by " " space. 6 2 4 5 3 9 1 8 7 5 1 9 7 2 8 6 3 4 8 3 7 6 1 4 2 9 5 1 4 3 8 6 5 7 2 9 9 5 8 2 4…
1 2 3
79
80