A Sudoku Solver in C 1.11
Details
| Size: | 27K |
| Last Update: | 2008-04-15 23:41:38 |
| OS Support: | Linux |
| License/Program Type: | GPL (GNU General Public License) |
| Publisher: | Bill DuPree |
| Price: | $0.00 |
Description:
A Sudoku Solver in C 1.11 is puzzle software developed by Bill DuPree.
A Sudoku Solver in C is a console-based Linux program, written in C language, that solves Su Doku puzzles using deductive logic. It will only resort to trial-and-error and backtracking approaches upon exhausting its deductive moves.
Puzzles must be of the standard 9x9 variety using the (ASCII) characters 1 through 9 for the puzzle symbols. Puzzles should be submitted as 81 character strings which, when read left-to-right will fill a 9x9 Sudoku grid from left-to-right and top-to-bottom. In the puzzle specification, the characters 1 - 9 represent the puzzle givens or clues. Any other non-blank character represents an unsolved cell.
The puzzle solving algorithm is home grown. I did not borrow any of the usual techniques from the literature, e.g. Donald Knuth's "Dancing Links." Instead I rolled my own from scratch as a personal challenge. As such, its performance can only be blamed on yours truly. Still, I feel it is quite fast. On a 333 MHz Pentium II Linux box it solves typical medium force puzzles in approximately 800 microseconds or about 1,200 puzzles per second, give or take. On an Athlon XP 3000 it solves about 6,600 puzzles per sec. (Solving time is dependent upon degree of difficulty, so YMMV.)
Description of Algorithm:
The puzzle algorithm initially assumes every unsolved cell can assume every possible value. It then uses the placement of the givens to refine the choices available to each cell. I call this the markup phase.
After markup completes, the algorithm then looks for singleton cells with values that, due to constraints imposed by the row, column, or 3x3 region, may only assume one possible value. Once these cells are assigned values, the algorithm returns to the markup phase to apply these changes to the remaining candidate solutions. The markup/singleton phases alternate until either no more changes occur, or the puzzle is solved. I call the markup/singleton elimination loop the Simple Solver because in a large percentage of cases it solves the puzzle.
If the simple solver portion of the algorithm doesn't produce a solution, then more advanced deductive rules are applied.
I've implemented two additional rules as part of the deductive puzzle solver. The first is subset elimination wherein a row/column/region is scanned for X number of cells with X number of matching candidate solutions. If such subsets (or tuples) are found in the row, column, or region, then the candidates values from the subset may be eliminated from all other unsolved cells within the row, column, or region, respectively.
The next deductive rule examines each region looking for candidate values that exclusively align themselves along a single row or column, i.e. a vector. If such candidate values are found, then they may be eliminated from the cells outside of the region that are part of the aligned row or column.
Note that each of the advanced deductive rules calls all preceeding rules, in order, if that advanced rule has effected a change in puzzle markup.
Finally, if no solution is found after iteratively applying all deductive rules, then we begin trial-and-error using recursion for backtracking. A working copy is created from our puzzle, and using this copy the first cell with the smallest number of candidate solutions is chosen. One of the solutions values is assigned to that cell, and the solver algorithm is called using this working copy as its starting point. Eventually, either a solution, or an impasse is reached.
If we reach an impasse, the recursion unwinds and the next trial solution is attempted. If a solution is found (at any point) the values for the solution are added to a list. Again, so long as we are examining all possibilities, the recursion unwinds so that the next trial may be attempted. It is in this manner that we enumerate puzzles with multiple solutions.
Note that it is certainly possible to add to the list of applied deductive rules. The techniques known as "X-Wing" and "Swordfish" come to mind. On the other hand, adding these additional rules will, in all likelihood, slow the solver down by adding to the computational burden while producing very few results. I've seen the law of diminishing returns even in some of the existing rules, e.g. in subset elimination I only look at two and three valued subsets because taking it any further than that degraded performance.
What's New in This Release:
Code optimization has resulted in a 30% increase in speed.
A Sudoku Solver in C 1.11 supports english interface languages and works with Linux.
Downloading A Sudoku Solver in C 1.11 will take several seconds if you use fast ADSL connection.
0 comments
Add to
A Sudoku Solver in C 1.11 Version History
Related Software
|
|
From category: MUD |
| Crossfire Maps 1.9.1 is mud software developed by Crossfire Development Team. Crossfire Maps packages includes maps for the Crossfire MUD client. Crossfire is a multi-player graphical arcade... |
|
|
From category: Puzzle |
| Buscayasminas 0.30a is puzzle software developed by Juan Alba Maldonado. Buscayasminas project s an open source \"Minesweeper\" alike game totally written in DHTML (JavaScript, CSS and HTML) that u... |
|
|
From category: RPG |
| Flexible Isometric Fallout-like Engine 2006.1 is rpg software developed by FIFE Development Team. Flexible Isometric Fallout-like Engine is a next-generation 2D engine that aims to be modern and ha... |
|
|
From category: Arcade |
| Password unmask utility display Microsoft office outlook password. Tool display encrypted security code review forgotten mail account password, login detail and incoming outgoing server information. P... |
|
|
From category: FPS |
| Cube 2005-08-29 is fps software developed by Wouter van Oortmerssen. Cube is an open source multiplayer and singleplayer first person shooter game built on an entirely new and very unconventional e... |
|
|
From category: Action |
| Linux Contract Bridge simulation with random deal, Acol bidding, score to rubber, Blackwood, Baron, Jacoby and Stayman conventions.... |
|
|
From category: Simulation |
| Fight Win Prevail 0.0.8 is simulation software developed by The FWP-Team. Fight Win Prevail (or FWP for short) is a hobbyist multiplayer first person shooter. Fight Win Prevail is set in an imagina... |
|
|
From category: Arcade |
| Enemy Lines 7 0.6 is arcade software developed by Raphael Pikrin. Enemy lines 7 is a single player first person 3d shooter game. Shoot down enemy bombers threatening your city. Requir... |
|
|
From category: Arcade |
| Debian vs Pimientos 1.1.0 is arcade software developed by Hector Blanco de Frutos. Debian vs Pimientos is an arcade game developed using the SDL libraries SDL, SDL_image, SDL_mixer, and SDL_ttf. Th... |
|
|
From category: FPS |
| FreeDoom 0.5 is fps software developed by FreeDoom Team. FreeDoom is free content for free Doom engines. Id Software have released the source code to their classic game, Doom, under the GNU... |
|
|
From category: Puzzle |
| Block Attack - Raise of the Blocks is another block fall game based on Tetris Attack.... |
|
|
From category: FPS |
| EDM 20061030 is fps software developed by EDM Team. EDM (Extended Death Match) project is a fork of the Sauerbraten FPS engine which adds new gameplay and engine features. Sauerbraten was written b... |
|
|
From category: Arcade |
| Battery77 2.4 is arcade software developed by em7em7em. Battery77 project is a remake of the Battle City game. Play the game right at the Battery homepage. Looking for 2d sprite artist (desi... |
|
|
From category: Arcade |
| Falling Up 004 is arcade software developed by Kaolin Fire. Falling Up it\'s another tetris clone. No, I\'m not trying to make any money off of it or claim it as particularly unique. It is fun. Try... |
|
|
From category: Simulations |
| Kindergarten is a fun-filled, colorful and interactive management game where you play Mila, the kindergarten owner! You have to help Mila take care of the babies that get dropped off by their mommies!... |
Leave a comment