sudoku

Optimizing the backtracking algorithm solving Sudoku

拜拜、爱过 提交于 2019-11-30 00:34:58
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, and get the list of values. From the list of values, I will loop through it by placing one of the values from the list in the slot, and recursively solve it, until the entire grid is filled. This implementation still takes incredibly long for some puzzles and I hope to further optimize this. Does anyone have any ideas

Why is translated Sudoku solver slower than original?

廉价感情. 提交于 2019-11-29 18:18:50
I transcribed my Java Sudoku solver into python. Everything works, however solving takes up to 2mins, while the identical puzzle takes only a few seconds in Java. Also the iterations needed amount to the exact same number. Am I missing something? import numpy as np def solve_recursive(puzzle, pos): if(pos == 81): print puzzle return True if(puzzle[pos] != 0): if (not solve_recursive(puzzle, pos+1)): return False else: return True row = np.copy(puzzle[pos//9*9:pos//9*9+9]) col = np.copy(puzzle[pos%9::9]) short = (pos%9)//3*3 + pos//27*27 square = np.concatenate((puzzle[short:short+3],puzzle

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

对着背影说爱祢 提交于 2019-11-29 15:56:27
问题 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 last year . 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

Bash simplified sudoku

孤人 提交于 2019-11-29 13:03:38
So,I have to write a bash script to check if a 9x9 "sudoku" solution is valid,but the simplification is that I don't have to divide it into 3x3,but just check if rows and columns contain any duplicate numbers,and valid numbers are only 1-9.. this is what I had in mind,but couldn't get it working: #!/bin/bash error="false" count=0 #this would be for columns #for i in 1 2 3 4 5 6 7 8 9 #do #cat sudoku.txt | awk -F "\t" '{ print $'$i'}' | uniq -c | awk '$1 > 1 { count++ } END { print count }' #done #and this would be for rows for i in 1 2 3 4 5 6 7 8 9 do cat sudoku.txt | awk '{ print FNR=$'$i'}'

Recursive solution to Sudoku generator

流过昼夜 提交于 2019-11-29 10:23:43
I'm trying to code an algorithm that creates a legal Sudoku board in either Java or Javascript. Neither work, and I'm not entirely sure why. Essentially, the problem in both programs is that either x or y is getting incremented more than it should (skipping the square). I can't for the life of me figure out how this is happening. I can provide the HTML that completes the JS solution if need be. My best guess is it has to do with how I've created a stack using recursion, but as far as I can tell, it should work. In my old code there was an incorrect for loop, I'm aware of this. I pasted an old

Algorithm Complexity (Big-O) of sudoku solver

别说谁变了你拦得住时间么 提交于 2019-11-29 10:07:06
I'm look for the "how do you find it" because I have no idea how to approach finding the algorithm complexity of my program. I wrote a sudoku solver using java, without efficiency in mind (I wanted to try to make it work recursively, which i succeeded with!) Some background: my strategy employs backtracking to determine, for a given Sudoku puzzle, whether the puzzle only has one unique solution or not. So i basically read in a given puzzle, and solve it. Once i found one solution, i'm not necessarily done, need to continue to explore for further solutions. At the end, one of three possible

Building a GUI for a Sudoku Solver (Complete with ASCII Example)

一曲冷凌霜 提交于 2019-11-29 06:23:58
问题 . OVERVIEW, SAMPLE Hello everyone, I have created a basic Sudoku solver that can solve most problems fairly quickly. I still have a lot of work ahead of me to make it solve even the hardest problems, but I'd like to try to implement a basic JFrame GUI first. I have worked with internet applets in the past, but never before with JFrames. I want to create something similar to the image below (for starters): ----------------------------------------------------------------------------------------

Sudoku solver in Java, using backtracking and recursion

我只是一个虾纸丫 提交于 2019-11-28 08:59:25
I am programming a Sudoku solver in Java for a 9x9 grid. I have methods for: printing the grid initializing the board with given values testing for conflicts (if same number is in same line or 3x3 sub-grid) a method to place the digits, one by one, which requires the most work. Before I go into detail with that method, keep in mind that I have to use recursion to solve it, as well as backtracking (watch the applet here as an example http://www.heimetli.ch/ffh/simplifiedsudoku.html ) Also, I am solving this Sudoku by moving vertically downwards, starting from the top left, through the first

Bash simplified sudoku

杀马特。学长 韩版系。学妹 提交于 2019-11-28 06:51:38
问题 So,I have to write a bash script to check if a 9x9 "sudoku" solution is valid,but the simplification is that I don't have to divide it into 3x3,but just check if rows and columns contain any duplicate numbers,and valid numbers are only 1-9.. this is what I had in mind,but couldn't get it working: #!/bin/bash error="false" count=0 #this would be for columns #for i in 1 2 3 4 5 6 7 8 9 #do #cat sudoku.txt | awk -F "\t" '{ print $'$i'}' | uniq -c | awk '$1 > 1 { count++ } END { print count }'

Recursive solution to Sudoku generator

跟風遠走 提交于 2019-11-28 03:53:37
问题 I'm trying to code an algorithm that creates a legal Sudoku board in either Java or Javascript. Neither work, and I'm not entirely sure why. Essentially, the problem in both programs is that either x or y is getting incremented more than it should (skipping the square). I can't for the life of me figure out how this is happening. I can provide the HTML that completes the JS solution if need be. My best guess is it has to do with how I've created a stack using recursion, but as far as I can