12,450,886 members (49,407 online)
Add your own
alternative version

14.1K views
348 downloads
12 bookmarked
Posted

# Logical Sudoku Solver

, 8 Nov 2007
 Rate this:
Please Sign up or sign in to vote.
Utilize logical rules and scanning to solve soduku puzzle, no guessing

## Introduction

I played sudoku for a while, then I just want to write something that solves the puzzle like I do. Following is an example I used with debugmode = false, if anybody doesn't like this part, please let me know, I will be happy to remove it from the screen and from my code.

```7  |  2|9
3 | 4 |
2  |1  |  8
-----------
5|  7|
42 |   | 35
|3  |8
-----------
5  |  4|  9
| 8 | 5
1|2  |  7

=======================================

7  |  2|9
3 | 4 |
2  |1  |  8
-----------
3 5|4 7|
42 |   | 35
|3  |8
-----------
5  |  4|  9
| 8 | 5
1|2  |  7

=======================================

7  |  2|9
3 | 4 |
2  |1  |  8
-----------
385|4 7|
42 |   | 35
|3  |8
-----------
5  |  4|  9
| 8 | 5
1|2  |  7

=======================================

7  |  2|9
3 | 4 |
2  |17 |  8
-----------
385|4 7|
42 |   | 35
|3  |8
-----------
5  |  4| 89
| 8 | 5
8 1|2  |  7

=======================================

7  |  2|91
3 | 4 |
2  |17 |  8
-----------
385|4 7|
42 |   | 35
|3  |8 4
-----------
5  |  4| 89
| 8 | 5
8 1|2  |  7

=======================================

7 4|  2|91
13 | 4 |
2  |17 |  8
-----------
385|4 7|
42 |   | 35
1 |3  |8 4
-----------
5  |  4| 89
| 8 | 5
8 1|2  |  7

=======================================

7 4|8 2|91
138| 4 |
2  |17 |  8
-----------
385|4 7|
42 |   | 35
1 |3  |8 4
-----------
5  |  4| 89
| 8 | 5
8 1|2  |  7

=======================================

7 4|8 2|91
138|54 |
2  |17 |  8
-----------
385|4 7|
42 |  8| 35
1 |3  |8 4
-----------
5  |  4| 89
| 8 | 5
8 1|2  |  7

=======================================

754|8 2|91
138|549|
2  |17 |5 8
-----------
385|4 7|
42 |  8| 35
1 |3  |8 4
-----------
5  |  4| 89
| 81| 5
8 1|2  |  7

=======================================

754|862|913
138|549|
2  |173|548
-----------
385|4 7|  1
42 |  8| 35
1 |3  |8 4
-----------
5  | 34|189
| 81| 5
8 1|2  | 67

=======================================

754|862|913
138|549|  6
2  |173|548
-----------
385|4 7|6 1
42 | 18| 35
1 |3 6|8 4
-----------
5 2| 34|189
3| 81| 52
8 1|2 5|367

=======================================

754|862|913
138|549|276
2  |173|548
-----------
385|4 7|6 1
426|918|735
917|356|8 4
-----------
5 2| 34|189
6 3| 81|452
841|295|367

=======================================

754|862|913
138|549|276
269|173|548
-----------
385|427|691
426|918|735
917|356|824
-----------
572|634|189
693|781|452
841|295|367

Finished!!!```

## Using the code

program.cs contains
```Sudoku sudoku = new Sudoku();
//sudoku.debugmode = true;
//sudoku.writeLog = false;
sudoku.Test();
```
You can make debugmode = true to display those rules involved, also can write them to log if the console screen is not convenient to read it.

## Points of Interest

Nothing fancy, it would be better if I apply one rule at a time instead of all of them. Top1465 sudoku questions involve 'guessing', which, IMHO, ruins the fun of solving sudoku logically.

1.0 Created

## License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

## About the Author

 Software Developer (Senior) United States
No Biography provided

## You may also be interested in...

 Pro Pro

## Comments and Discussions

 First Prev Next
 A minor quibble. Humble Programmer8-Nov-07 9:11 Humble Programmer 8-Nov-07 9:11
 Re: A minor quibble. H. Tony8-Nov-07 9:43 H. Tony 8-Nov-07 9:43
 Last Visit: 31-Dec-99 18:00     Last Update: 27-Aug-16 5:55 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160826.1 | Last Updated 8 Nov 2007
Article Copyright 2007 by H. Tony
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid