Question:
Sudoku Puzzle Solver Please Help (C++)?
1970-01-01 00:00:00 UTC
Sudoku Puzzle Solver Please Help (C++)?
Five answers:
?
2016-12-04 01:12:16 UTC
shade code the numbers, much less confusing to your suggestions to technique the varieties! that's in spite of each thing, knitting with numbers. consistently seem for the numbers in line, then packing packing containers. something is in basic terms a mix of the two. coaching and you will discover out extra connections between the packing packing containers and strains. understand that if the different 2 of the 3x3 packing packing containers already have numbers which at the instant are not interior the line you're engaged on, then the selection would be interior the three squares of that different container. this is one clue many fail to understand. try working in direction of to work out extra varieties. It enables to have an outstanding memory, Sudoku can require you to recollect previous clues alot of the time. that's recommended to mark out contemporary famous and new clues in accordance to the order you locate them. additionally, there is not any success in touch in Sudoku, or "opportunities and opportunities." each and each selection has it truly is set of "clues", consistently understand that! not at all ever try your success no remember how probably and plausible it style of feels. you will get fortunate yet you will not at all strengthen like that. better of all, try this with a buddy, it enables that somebody else is going nuts with you once you fail to sparkling up the puzzle. take excitement in.
husoski
2011-07-02 20:42:07 UTC
I wrote my solver in Python, which made the task a bit easier. After getting all the bits working in text mode, I packed the computation parts into an object ("engine") and added a GUI front-end. All the GUI had to do was provide a nice way to enter the board, a "Solve" button, and be able to display the solutions returned by the "engine".



That worked pretty well. Concentrate on one thing at a time. Leave GUI till later. My first "board setup" was a an array initialization in the source code. To change the board setup I had to edit the source and rerun.



The "backtracking" idea is simple. Try a move, and if it doesn't work out, undo that move and try another. It's also called "Ariadne's Thread" or sometimes "guess and check". If you allow for the possibility of multiple solutions, as when testing a composed or generated puzzle, then this is the primary way to solve Sudoku boards. Most human "by logic" methods lean partially or wholly on the existence of a unique solution.



Recursion is the easiest way to implement such a search for solutions. It takes a bit of care about how you pick "guess" moves to make so that you don't end up with a gazillion copies of the same solution reached by different sequences of moves, though.
modulo_function
2011-07-02 19:34:54 UTC
In my introductory C++ class at SFSU we wrote a solver. We were given quite a bit of help. What we did was generate a row of values that satified constraints, ie, no row dups and no column dups. We tried a number of times to do this and if we couldn't then we'd back up a and regenerate the previous row.



You can search and find lots of help and even some code. Here's a link to one source:
Person
2011-07-02 18:25:26 UTC
You could always try a backtracking algorithm. It's inefficient, but it works.



If you want to get more advanced, you could try building a neural network for it, but that might be well beyond where you are now.



Look it up. There's plenty of info and code examples all over the internet.
?
2011-07-02 19:19:54 UTC
Backtracking algorithm:

Main()

Create a 9x9 array to hold the sudoku.

Populate the sudoku.

call solve, passing the sudoku and values (0,0,0) - representing the last row, column, and # you tried.

Check the return value. If false, report no solution else print solution.



Solve()

Each cell can either be solved or empty. Iterate cells from the passed cell reference until you find one that is empty or you have solved all cells. If you have solved all cells, return success.

If that cell passed is the cell passed in, increment the # to attempt. Else, start with 1.

Check the cell to see if # can legally be placed. If not, increment #.

If no number from 1 to 9 can legally be placed, exit Solve with a failure.

Else if you can find a legal move, call Solve recursively with the new grid.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...