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

Sudoku Solver in python not printing board

I have been working on a python program to solve a sudoku puzzle, but I am not sure what I did wrong. I thought i had fixed it but now I cannot get it to print the board or solve it. I have already written the algorithm to solve as well as the…
qmayo14
  • 11
  • 3
-2
votes
1 answer

Leetcode not accepting correct sudoku solver algorithim

I wrote a sudoku solver in Javascript for https://leetcode.com/problems/sudoku-solver/solution/. Whenever I use the same code in an IDE outside of leetcode, it solves the sudoku board fine. However, when I submit it as an answer in leetcode, it…
-2
votes
1 answer

N-Queens program in Python

The N Queen is the problem of placing N chess queens on an N×N chessboard so that no two queens attack each other. I have solved this program earlier, but am trying to rework my code to mirror that which I used to fashion a sudoku solver. I cannot…
Akashvshroff
  • 181
  • 1
  • 9
-2
votes
1 answer

Can someone help explain the recursion in this back tracking algorithm?

This is a program that solves a sudoku board using python and the back-tracking algorithm, but I don't seem to understand the recursion in solve(bo). Like it seems like if the condition is not met, then the index is reset to 0 and it continues to…
CodingBoy
  • 39
  • 1
  • 9
-2
votes
1 answer

Sudoku: Valid values in a position

I'm trying to figure how answer to these question in my code: create a method called getValidValues that: returns an array of 9 boolean values that corresponds to 9 digits (1-9) and, it is true if that digit can be placed in that position…
-2
votes
1 answer

I want to make a for loop, but it won't compile

for(sudoku.get((int)(0)).doubleValue(); == sudoku.get((int)(1)).doubleValue();) { sudoku.remove((int)(1)); Sudoku.add(Double.valueOf(SketchwareUtil.get random((int)(1)), ((int)(9)))); } The error wants me to remove the "==" in the…
-2
votes
2 answers

Can't make a slice of a column of a 2d array "cannot use Sudoku[0:9][0] (type [9]int) as type []int in assignment"

I'm making a simple game of sudoku using slices of a 9x9 2d array. I'm still starting out with Golang and have some C++ experience. I keep getting the error message "cannot use Sudoku[0:9][0] (type [9]int) as type []int in assignment". var row1…
Zbadrawy
  • 13
  • 2
-2
votes
1 answer

C# Sudoku Board Generator

First off, yes I have searched and no I did not find a relevant answer to my question. I am trying to create a Sudoku Board in C#. I believe my cells are correct and my "Game board" class is correct, however I cannot get an actual board generated. I…
DrJagaloon
  • 19
  • 4
-2
votes
1 answer

Java - Add background to every square in a 9x9 grid

I would like to make in JavaFX a 9x9 sudoku grid like in this image Any idea how to do it in a nice way? Thanks Edit: I managed to do it, but the code doesn't look so good. private void addBackground(StackPane cell, int row, int col) { String[]…
-2
votes
2 answers

Checking for validity in 2d array

so i am creating a sudoku validity checker program in C++. the program takes in a csv file with an already completed sudoku board. the program is supposed to read the file line by line and put the numbers into a 2d array (which it's doing just…
Marc Karam
  • 445
  • 6
  • 22
-2
votes
1 answer

Sudoku solver in python with backtracking

I saw a few sudoku solvers implementations ,but I cant figure out the problem in my code. I have a function sudokusolver which becomes sudoku Board and must return solved sudoku board. def sudokutest(s,i,j,z): # z is the number isiValid =…
S Hristoskov
  • 53
  • 1
  • 9
-2
votes
1 answer

c sudoku solver with recursive backtracking returning errors

Hey everyone so I wrote a sudoku solver in C that uses recursive backtracking. However the output is not what's expected.For the code to work you need to pass in an array of 81 numbers, and the 0 on the board equals a '.' in the array. The problem…
-2
votes
2 answers

My Program Is Trapped In A Weird Freeze/Infinite Loop

I am writing a Sudoku App In VB.NET. Currently I am working on the implementation for a Sudoku puzzle generator. The one I have written is having a weird issue where the application just comes to a standstill. At first I just rationally assumed that…
Null Spark
  • 35
  • 8
-2
votes
1 answer

Every possible permutation of a set of arrays

I've got a hash like this: Each key represents a row number on a Sudoku board. Each array in a value represents a possible solution for that row possibilities = { 1 => [[1, 1, 1], [1, 1, 1], [1, 1, 1]], 2 => [[2, 2, 2], [3, 3, 3], [4, 4, 4]], …
Dylan Richards
  • 796
  • 3
  • 9
  • 26
-2
votes
1 answer

textView setText() and append() crashing when OnClick function is called

I'm making a Sudoku app and I want to add a Move Counter so I have a textView that is displayed with the movecount every time the user inputs a number public class NumberButton extends Button implements OnClickListener { private int number; …