sudoku

Mini sudoku solver in Prolog stops partway through

筅森魡賤 提交于 2019-12-09 18:40:44
问题 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 for whatever reason, but swi-prolog worked first try). I am running Ubuntu 10.04 in VirtualBox 4.0.4 r70112 (hopefully that's not too relevant!) Here is the code in my prolog file: :- use_module(library(clpfd)). valid([]). valid([Head|Tail]) :- all

Unique methods to generate sudoku puzzle [duplicate]

a 夏天 提交于 2019-12-09 10:31:07
问题 This question already has answers here : How to generate Sudoku boards with unique solutions (9 answers) Closed 5 years ago . How many possible unique ways are there to generate a Sudoku Puzzle?? I can think of only two possible ways 1) Take a solved Sudoku puzzle and shuffle the rows and columns 2) Generate a random number and check if it violates any Sudoku constraints, repeat untill number does not violate any Sudoku constraint for every square(theoretically possible but normally it leads

How to Generate a -complete- sudoku board? algorithm error

99封情书 提交于 2019-12-08 23:30:45
问题 I'm trying to generate a complete (ie, each cell filled with a number) Sudoku-like board. It's for something else that has nothing to do with sudokus, so I am not interested in reaching a sudoku with white squares that can be solved, or anything that has to do with sudokus. Don't know if you know what I mean. I've done this in java: private int sudokuNumberSelector(int x, int y, int[][] sudoku) { boolean valid = true; String validNumbers = new String(); int[] aValidNumbers; int squarexstart =

On Sudoku solving

风流意气都作罢 提交于 2019-12-07 08:20:21
问题 Can someone please help me understand this solution: Initialize 2D array with 81 empty grids (nx = 9, ny = 9) Fill in some empty grid with the known values Make an original copy of the array Start from top left grid (nx = 0, ny = 0), check if grid is empty if (grid is empty) { assign the empty grid with values (i) if (no numbers exists in same rows & same columns same as (i) & 3x3 zone (i) is currently in) fill in the number if (numbers exists in same rows & same columns same as (i) & 3x3

I don't understand what label does in Prolog

烈酒焚心 提交于 2019-12-07 00:30:24
问题 I went through the manual and documentation but still don't understand. I'm trying to implement a sudoku solution where after writing out all the other rules of the game, I've added label(Board) according to my teacher's instructions. However I still don't get how it works or what it's doing. Shouldn't the other constraints(I have checks saying numbers have to be 1..9, row has to be all different,etc) give me the answer by themselves? 回答1: If you want to learn Prolog and CLP(FD) rapidly, use

Building an EFFICIENT Sudoku Solver

廉价感情. 提交于 2019-12-06 00:14:09
问题 Yes, I know this is nothing new and there are many questions already out there (it even has its own tag), but I'd like to create a Sudoku Solver in Java solely for the purpose of training myself to write code that is more efficient. Probably the easiest way to do this in a program is have a ton of for loops parse through each column and row, collect the possible values of each cell, then weed out the cells with only one possibility (whether they contain only 1 number, or they're the only cell

Finding characters in a string that occur only once

青春壹個敷衍的年華 提交于 2019-12-05 20:34:48
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 Square s to represent the board. The implementation of the algorithm I'm using is a sort of triple-tier approach. The first step, which will solve only the most basic puzzles (but is the most efficient), is to fill in any squares which can only take a single value based on the board's initial setup, and to adjust the constraints accordingly on the rest of the

Java sudoku generator not working correctly

左心房为你撑大大i 提交于 2019-12-05 18:53:36
I have been working on a sudoku puzzle generator in java, I wrote this class to generate the puzzle but it is not correctly generating the puzzle. Here is an example of what I am getting: As you can see this is not a valid sudoku solution. But looking at my code, I don't understand why it is not generating a valid puzzle. Can someone explain why this does not work correctly? package sudoku; import java.util.Random; public class Puzzle { // number generator Random gen = new Random(); // 9x9 puzzle int puzzle[][] = new int[9][9]; public int[][] generate() { // add each number to the board for

On Sudoku solving

让人想犯罪 __ 提交于 2019-12-05 17:40:04
Can someone please help me understand this solution : Initialize 2D array with 81 empty grids (nx = 9, ny = 9) Fill in some empty grid with the known values Make an original copy of the array Start from top left grid (nx = 0, ny = 0), check if grid is empty if (grid is empty) { assign the empty grid with values (i) if (no numbers exists in same rows & same columns same as (i) & 3x3 zone (i) is currently in) fill in the number if (numbers exists in same rows & same columns same as (i) & 3x3 zone (i) is currently in) discard (i) and repick other values (i++) } else { while (nx < 9) { Proceed to

Mini sudoku solver in Prolog stops partway through

好久不见. 提交于 2019-12-04 10:07:45
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 for whatever reason, but swi-prolog worked first try). I am running Ubuntu 10.04 in VirtualBox 4.0.4 r70112 (hopefully that's not too relevant!) Here is the code in my prolog file: :- use_module(library(clpfd)). valid([]). valid([Head|Tail]) :- all_different(Head), % in the book, this is 'fd_all_different' valid(Tail). % beginning of sudoku rule