sudoku

Replace all zeros in array with elements of another array

纵然是瞬间 提交于 2019-12-13 07:49:57
问题 Say I've got an array like this: array_1 = [0, 0, 1, 2, 3, 0] and another one like this: array_2 = [4, 5, 6] How can I create an array like this, such that each 0 in the array_1 is replaced by the first and subsequent elements of the array_2 ?: [4, 5, 1, 2, 3, 6] That is, every time we encounter a 0 in the first array, we'd like to replace it with the result of array_2.shift . 回答1: This one is shorter but the shift method it will modify array_2 in-place. array_1.map {|x| x == 0 ? array_2

Why is this sudoku backtracking getting stuck?

▼魔方 西西 提交于 2019-12-13 06:35:51
问题 I'm writing a sudoku backtracking solver, it's getting stuck and I don't understand why. I think my recursive calls are alright. What I'm missing? Input is read from input.txt file with the grid initial layout in a single line: input.txt: 004020000201950070090004852005490001006000900800051300958100020010072608000080500 Edit: I mean 'stuck' as not finishing its solving of the grid This is a sample output: current move count is 6 3 6 4 7 2 8 1 9 0 2 0 1 9 5 0 0 7 0 0 9 0 0 0 4 8 5 2 0 0 5 4 9 0

Sudoku - Region testing

核能气质少年 提交于 2019-12-13 05:24:15
问题 I'm creating a sudoku generator, using a 'brute-force' randomity approach. I have been able to check the x / y axis for duplicate numbers just fine using the code: for(l=0; l<9; l++){//Makes all vertical work. if(sudoku[l][j] == temp){ isUsed=true; } } for(m=0; m<9; m++){//makes all horizontal work if(sudoku[i][m] == temp){ isUsed=true; } } I decided to implement the 'box' or 'region' checking (where you check every 3x3 square from the origin) and I just can't seem to wrap my head around the

How to get the Sudoku 2D-array index, given its “sub-grid” and “cell-in-the-sub-grid” indexes?

做~自己de王妃 提交于 2019-12-13 02:15:12
问题 I'm working on a sudoku thing, and I'm having trouble reducing one part of it. I'm designing a SudokuBoard object to have an underlying 2D byte array, and three different views of that array: row-units, column-units and grid units. A grid is the nine-by-nine blocks, indexed like this: GRID INDEX | | 0 | 1 | 2 | | ------------------------- | | 3 | 4 | 5 | | ------------------------- | | 6 | 7 | 8 | | Where each grid has nine cells, indexed like this CELL INDEX 0 1 2 3 4 5 6 7 8 Here is the 2d

Sudoku backtracking algorithm (Java)

橙三吉。 提交于 2019-12-13 01:27:17
问题 I've created a Sudoku solver that will solve a Sudoku as a human might- by checking possibilities + definite values in squares corresponding to the square being checked. (Source: http://pastebin.com/KVrXUDBF) However, I would like to create a random Sudoku generator (from a blank grid), and so have decided to use a backtracking algorithm. I understand the concept of backtracking, but am confused about one thing: How do I know which previous node to return to (and change) once I know a certain

Prolog Ambiguous Output

与世无争的帅哥 提交于 2019-12-12 18:14:29
问题 I'm writing a mini sudoku solver in Prolog. The sudoku consists of 4x4 fields, e.g. _ _ 2 3 _ _ _ _ _ _ _ _ 3 4 _ _ If the sudoku is has only one possible solution (as the sudoku above), my program works as expected. But if I replace at least one given field with a gap (e.g. by replacing 4 by _), the output of Prolog is like this: [_#3(1:4),_#23(1:4),2,3..... I guess "_#3(1:4)" means "take 1 or 4", but I want each solution in a separated, non-ambiguous list. This is my code: sudoku(Puzzle

Brute force sudoku solver algorithm in Java problem

廉价感情. 提交于 2019-12-12 12:24:32
问题 Everything seems to work fine in the algorithm besides the solve method. When it executes the program using a solvable Sudoku board, it says that it cannot be solved. I've tried everything I can think of in the solve method. I've tried debugging and it fails after the first row is tested. Any suggestions? Here is the full code so far: public class SudokuSolver { public static void initializeGrid(int[][] grid, int[][] puzzle) { for (int r = 0; r < puzzle.length; r++) { for (int c = 0; c <

What is wrong with this char array code?

被刻印的时光 ゝ 提交于 2019-12-12 10:15:41
问题 I'm new to C++, only been programming a few days so this might seem stupid, but can you spot why my arrays are not working correctly? This is the start of a program I'm designing that will solve Sudoku puzzles, but the 2D array that I'm using to solve it isn't working correctly. #include <iostream> #include <string> using namespace std; int main () { char dash[9][9]; for (int array=0; array<9; array++) { for (int array2=0; array2<9; array2++) { dash[array][array2]=array2; cout << dash[array]

How to get input from another file for my Sudoku game C using a .txt file

瘦欲@ 提交于 2019-12-12 05:27:30
问题 Alright so my problem is that I have no idea where to go in my situation with my Sudoku Program. As of right now I have multiple programs that work together to create my Sudoku program which is SUPPOSED to take input of 9 lines with 9 characters each whether it be just spaces or numbers. example: 53 7 6 195 98 6 8 6 3 4 8 3 1 7 2 6 6 28 419 5 8 79 What the program would yield would be: 534678912 672195348 198342567 859761423 426853791 713924856 961537284 287419635 345286179 My current

Sudoku generation speed

依然范特西╮ 提交于 2019-12-12 02:48:06
问题 I wrote a backtracking algorithm to generate sudokus with arbitrary size. My problem is the varying speed of this generation algorithm. I added some console output to see the results. I generated ~20 Sudokus with the size of 16x16, each one had 1ms to 150ms generating time. The next one took over 10 minutes, and it didn't even finish. (I stopped the program). In consideration of that, I think I made a mistake in the backtracking implementation, which prevents the algorithm from advancing.