sudoku

How to make Sudoku solver with backtracking algorithm go back?

点点圈 提交于 2019-12-22 10:49:50
问题 This weekend I worked on a Sudoku Solver (Ruby quiz) based on a backtracking algorithm. The sudoku is loaded in an array sudoku_arr of 81 integers (9x9 grid) where 0's are empty spots. There is a valid? method which checks if the sudoku_arr can be a valid sudoku. The official backtracking algorithm goes like this: try value on next empty spot, check if it is valid sudoku, if not increase value by 1 (upto 9), if valid go on and try first value on next spot, if not increase value of previous 0.

Random sudoku generation

妖精的绣舞 提交于 2019-12-21 21:38:01
问题 I'm writing a function that should generate random sudoku puzzles for a simulation project; this funcion takes as argoument the number of cells to generate then it generates the indexes of cells and numbers to put in those cells. I have a problem in generation of cells indexes, I'm not an expert in programming and i can't find a good routine to generate indexes and to check out not to be the same index couple two times or more. The funcion is: void gen_puzzle(int quanti) { if(quanti>81) exit

Prolog predicate with variable number of arguments [closed]

。_饼干妹妹 提交于 2019-12-21 17:28:35
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . I am writing a Sudoku-Solver with PROLOG. I want the solver to work with all possible sizes of Sudokus, so naturally I need to construct predicates which take a variable number of arguments. (For example to construct the "blocks" in the Sudoku.) How can I construct or simulate

Sudoku solving algorithm with back-tracking

ⅰ亾dé卋堺 提交于 2019-12-21 04:23:12
问题 I'm looking to implement a very simple algorithm that uses brute-force back-tracking to solve Sudoku grids. The problem I'm facing is that in my implementation I included two instance variables for a Sudoku class called row and col , which correspond to the row and column of an empty cell in a two dimensional array that represents the Sudoku grid. When my solve() method executes it first checks to see if there aren't any empty cells, in which case the puzzle is already complete. Otherwise,

Brute force Algorithm for creation of Sudoku Board

五迷三道 提交于 2019-12-21 02:34:24
问题 What I am developing is that initially the entire sudoku board is empty. One of the random cells(out of 81) is filled with a random value(1-9). Now I want to fill all the remaining cells using brute force approach. From what I came to know after googling is that we should start with the first cell and fill it with 1(if it's valid), then fill the second cell with 2(if it's valid, we will begin checking with a number greater than the last filled cell, which in this case is 1, once we reach 9,

Sudoku generator algorithm

可紊 提交于 2019-12-20 09:46:01
问题 I made an algorithm to generate sudokus, but it was terribly inefficient. Each puzzle took minutes to generate. So now I am trying to write it again in optimal way. But I am experiencing some problems I need help with. There are two aproaches, start with blank grid and add numbers, then check if it is solvable. Second approach is to create full valid grid with all 81 numbers and then remove until we are happy with number of remaining numbers and it is still solvable. First I used first

A cool algorithm to check a Sudoku field?

南楼画角 提交于 2019-12-20 08:38:49
问题 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 there must be a better (in the sense of more elegant) solution. Efficiency is quite unimportant. 回答1: You need to check for all the constraints of Sudoku : check the sum on each

Dynamic generate sudoku board table using javascript

安稳与你 提交于 2019-12-20 07:39:17
问题 I am trying to to generate a Sudoku board using this script: The problem is that I don't know how to validate to generate unique numbers on columns and squares. Actually is just validating and generating unique numbers only on rows. Here is that code : function generate(count, values) { return Array.apply(null, { length: count }).map(function () { var r = [], array = values.slice(); while (array.length) { r.push(array.splice(Math.floor(Math.random() * array.length), 1)[0]); } return r; }); };

Dynamic generate sudoku board table using javascript

巧了我就是萌 提交于 2019-12-20 07:39:11
问题 I am trying to to generate a Sudoku board using this script: The problem is that I don't know how to validate to generate unique numbers on columns and squares. Actually is just validating and generating unique numbers only on rows. Here is that code : function generate(count, values) { return Array.apply(null, { length: count }).map(function () { var r = [], array = values.slice(); while (array.length) { r.push(array.splice(Math.floor(Math.random() * array.length), 1)[0]); } return r; }); };

convert an 2d array from rows to blocks

情到浓时终转凉″ 提交于 2019-12-20 05:22:08
问题 I am trying to work in this code for weeks. I need to convert rows and columns in a 2d array to blocks. it should work on any matrix in size n*n. (that I have been given the size of the array) for example: this: int[][] input = {{1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}, {1,2,3,4,5,6,7,8,9}} ; this is need to be the output: {{1,2,3,1,2,3,1,2,3} {4,5,6,4,5,6,4,5,6} {7,8