11/23/2023 0 Comments Java solving sudoku puzzles![]() Here is the code as described below in my comment. Return false //no value for x fit in the current squareĮdit: its been a while since I've used arrays in Java, sorry if I screwed up any syntax. found for some future square, try again with a new x }// even though x fit in this square, an x couldn't be If makePuzzle(puzzle, i++) //find the next x ![]() If (i=80) return true //terminal condition, x fits in the last square The backtracking algorithm is a powerful technique commonly used to solve Sudoku puzzles. If (//x satisfies all three conditions for the current square i) I just made this up, but could something like this work? private boolean makePuzzle(int puzzle, int i) This thesis explores the reduction of a Sudoku puzzle to an exact cover problem and how an already existing exact cover solving algorithm finds a solution to it. For example, to look at the value below a number, add 9 to the index. A grid has 9 rows, 9 columns and 9 boxes (or blocks or regions), each having 9 cells (or squares), for. I think you can use a 1D array, in much the same way a 1D array can model a binary tree. the puzzle) is a partially completed grid. println("hey lets play a game of sudoku:take down the question and replace the 0's with your digits and complete the game by re entering your answer") Is there an "easier" way to go about doing this with any type of data construct aside from a 2d array? Is there an easier way to check each 3x3 region that might coincide with checking either vert or horizontal better? From a standpoint of computation I can't see too many ways to do it more efficiently without swelling the size of the code dramatically. As it iterated through it would do the same until the array was filled, but due to the fact that I was filling with rand, and checking each row / column / region multiple times it felt very inefficient. Once the 3 rows were done it would check the 3 rows, and 3 regions and each vertical col up to the 3rd position. The way that I went about solving this was by using a 2-dimensional array to place numbers at random, 3 rows at a time. Each row / col / region must use the numbers 1-9 only once. And I feel like I've somehow overcomplicated things by taking a very brute-force approach to generating the puzzles.Įssentially my goal is to create a 9x9 grid with 9- 3x3 regions. I finished the project and was able to create a sudoku generator, but it feels like it's contrived. In my last question seen here: Sudoku - Region testing I asked how to check the 3x3 regions and someone was able to give me a satisfactory answer (although it involved a LOT of tinkering to get it working how I wanted to, since they didn't mention what the class table_t was.)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |