sudoku

Shortest Sudoku Solver in Python - How does it work?

I was playing around with my own Sudoku solver and was looking for some pointers to good and fast design when I came across this: def r(a):i=a.find('0');~i or exit(a);[m in[(i-j)%9*(i/9^j/9)*(i/27^j/27|i%9/3^j%9/3)or a[j]for j in range(81)]or r(a[:i]+m+a[i+1:])for m in'%d'%5**18] from sys import*;r(argv[1]) My own implementation solve...

Smart Sudoku Golf

Hello all, The point of this question is to create the shortest not abusively slow Sudoku solver. This is defined as: don't recurse when there are spots on the board which can only possibly be one digit. Here is the shortest I have so far in python: r=range(81) s=range(1,10) def R(A): bzt={} for i in r: if A[i]!=0: con...

A cool algorithm to check a Sudoku field?

Hi, Does anyone know a simple algorithm to check if a Sudoku-Configuration is valid? The simplest algorithm I came up with is (for a board of size n) in Pseudocode for each row for each number k in 1..n if k is not in the row (using another for-loop) return not-a-solution ..do the same for each column But I'm quite sure ...

Finding characters in a string that occur only once

I'm writing an algorithm in PHP to solve a given Sudoku puzzle. I've set up a somewhat object-oriented implementation with two classes: a Square class for each individual tile on the 9x9 board, and a Sudoku class, which has a matrix of Squares to represent the board. The implementation of the algorithm I'm using is a sort of triple-tie...

Programming Design Help - How to Structure a Sudoku Solver program?

Hi, I'm trying to create a sudoku solver program in Java (maybe Python). I'm just wondering how I should go about structuring this... Do I create a class and make each box a object of that class (9x9=81 objects)? If yes, how do I control all the objects - in other words, how do I make them all call a certain method in the class? Do I j...

Retrieve and store elements (according to conditions) from an array.

Given an array of 81 elements (meant to represent a 9x9 grid) how can I go over each element, grabbing the three around it and then performing an operation on those, then continuing to the next three of each row, column, or submatrix. Look below or at a sudoku grid to see the layout. define COL(n) ((n) % 9) define ROW(n) ((n)...

Sudoku algorithm in C#

I need one liner (or close to it) that verifies that given array of 9 elements doesn't contain repeating numbers 1,2,3,...,9. Repeating zeroes do not count (they represent empty cells). The best I have came out so far is: var a = new int[9] {1,2,3,4,5,6,7,8,9}; var itIsOk = a.Join(a, i => i, j => j, (x, y) => x) .GroupBy(y => y).Wh...

Astar-like algorithm with unknown endstate

A-star is used to find the shortest path between a startnode and an endnode in a graph. What algorithm is used to solve something were the target state isn't specifically known and we instead only have a criteria for the target state? For example, can a sudoku puzzle be solved with an Astar-like algorithm? We dont know how the endstate ...

Multi-threaded algorithm for solving sudoku?

I have a homework assignment to write a multi-threaded sudoku solver, which finds all solutions to a given puzzle. I have previously written a very fast single-threaded backtracking sudoku solver, so I don't need any help with the sudoku solving aspect. My problem is probably related to not really grokking concurrency, but I don't se...

Java Sudoku Gui

Hey stackoverflow. I am currently writing a sudoku solver in java. What i need now is some kind of swing gui to input the already known numbers. I created a jframe but manually adding 81 textfields from the toolbox seems like a bad solution. I am also able to add the with something like this: this.setLayout(new GridLayout(9, 9)); ...

The Dancing Links Algorithm - An explanation that is less explanatory but more on implementation?

Hi, I've been working on a Sudoku Solver, my current solver uses the backtracking algorithm but it still takes too long. I'm hoping to get it down to less than a second for most cases. As such, I've decided to rewrite it with the dancing links algorithm, understanding it is one of the better bruteforce methods that works well especiall...

Optimizing the backtracking algorithm solving Sudoku

Hi, I'm hoping to optimize my backtracking algorithm for my Sudoku Solver. What it does now: The recursive solver function takes a sudoku puzzle with various given values. I will scour through all the empty slots in the puzzle, looking for the slot that has the least possibilities, get the list of values. From the list of values, ...

Sudoku Solver by Backtracking question update

Assuming a two dimensional array holding a 9x9 sudoku grid, where is my solve function breaking down? I'm trying to solve this using a simple backtracking approach. Thanks! bool solve(int grid[9][9]) { int i,j,k; bool isSolved = false; if(!isSolved(grid)) isSolved = false; if(isSolved) return isSolved; for(i=0; i<9; i++...

duplicacy problems while creating a sudoku puzzle

I am trying to create my own normal 9x9 sudoku puzzle. I divided the problem into two parts - creating a fully filled sudoku, and removing unnecessary numbers from the grid Right now, I am stuck with the first part. This is the algorithm I use in brief: a) first of all I choose a number (say 1), generate a random cell position,...

Algorithm for solving Sudoku

I want to write a code in python to solve a sudoku puzzle. Do you guys have any idea about a good algorithm for this purpose. I read somewhere in net about a algorithm which solves it by filling the whole box with all possible numbers, then inserts known values into the corresponding boxes.From the row and coloumn of known values the kno...

Sudoku table generator failure, lisp

Hello. I have a problem with some part of my lisp code. It is a sudoku table generator. It works fine until this part: (loop for e in entries do (if (and (not (member e sub)) (not (member e col))) (progn (setq choices (nconc choices (list e))) (print choices))) (if (= (length choices) 1) ...

Latin squares generator? (Sudoku-like constraint problem)

Purpose We're designing a Latin square (sudoku-like sequence) for an experimental design that needs to follow these constraints: Values cannot be repeated in a row Values cannot be repeated in a column Values cannot be repeated pairwise in any two rows Example for the first 3 constraints: 2 3 5 7 11 13 7 2 11 ...

Writing Sudoku Solver wih Python

Here is my Sudoku Solver written in python language, When I run this program there seems to be a problem with in Update function and Solve function. No matter how much time I look over and move the codes around, I seem to have no luck Can anyone Help me? import copy def display (A): if A: for i in range (9): ...

What kind of learning algorithm would you use to build a model of how long it takes a human to solve a given Sudoku situation?

I don't have much experience in machine learning, pattern recognition, data mining, etc. and in their underlying theory and systems. I would like to develop an artificial model of the time it takes a human to make a move in a given Sudoku puzzle. So what I'm looking for as an output from the machine learning process is a model that can...

How do I fix this stack overflow error?

So I have what I think is pretty good code for a sudoku solver in java but I need some help with this method. It gives me a stack overflow when I embed it in a main method. The problem is that my method doesn't know how to turn around and fix its mistakes. I need a boolean flag (one that, unlike the one used in the code below, actually w...