View previous topic :: View next topic |
Author |
Message |
haha01haha01 Grandmaster Cheater Supreme Reputation: 0
Joined: 15 Jun 2007 Posts: 1233 Location: http://www.SaviourFagFails.com/
|
Posted: Wed Apr 01, 2009 10:53 am Post subject: [C#] Sudoku Solver |
|
|
This is a sudoku solver made in C#. originally made it as an experiment with two-dimensional arrays, and decided to release it.
Downloads:
Compiled binary (64bit compatible)
Source code (C#)
How-to:
The 9x9 table is where you place all the numbers given to you. by clicking on the save button you can save the table to a .txt file (rows are separated by line break and columns by commas), and by clicking on load you can load a txt file into the table (honestly these two features were mainly for debugging because it was annoying to write all the numbers every time i needed to test something)
when you click on solve, the sudoku will be solved and the result will be put in the table. IF for some reason (shouldnt happen) it cant solve the sudoku, the unsolved blocks will be left blank.
How it works:
This sudoku solver uses two "Decryption" levels to solve the sudoku.
Decryption Level One:
This is a simple procedure that checks every empty block's options based on the other numbers in its row\column\3x3 square, and if there is only one option it fills that option and starts over. this works for easy-medium level sudokus. if there are still unsolved blocks after this procedure is done, it will automatically move to level two.
also, if there are zero options (not a bug, see level two) it will throw an array out of bonds exception, because it will try to select option #0 from an empty option list.
Decryption Level Two:
This is the brute force method, so it takes longer than level one. this procedure clones the current sudoku, finds an empty block, and creates a list of all the possible options it can be (there must be more than one option, because else it would have been solved in level one). then, it tries every option on a cloned sudoku, and tries to decrypt the clone in level one and than (recursively in) level two, and if none of the options succeed it throws an empty exception. if level one throws an exception, there must be something wrong, so it catches the exception and continues with the next number. if level two throws an exception, it means that none of options tried in level two were correct (considering the number tried in the parent level two), so it goes on to the next number.
Last edited by haha01haha01 on Thu Dec 17, 2009 4:52 am; edited 2 times in total |
|
Back to top |
|
|
Deve Expert Cheater Reputation: 0
Joined: 20 Jan 2007 Posts: 245 Location: Stockholm, Sweden
|
Posted: Wed Apr 01, 2009 11:34 am Post subject: |
|
|
interesting application there i'll make sure to use it
_________________
Leecher. |
|
Back to top |
|
|
haha01haha01 Grandmaster Cheater Supreme Reputation: 0
Joined: 15 Jun 2007 Posts: 1233 Location: http://www.SaviourFagFails.com/
|
Posted: Thu Apr 02, 2009 8:04 am Post subject: |
|
|
some weird bug i just found, if you just enter the numbers into the table it wont work. you have to save them to file and than load it.
|
|
Back to top |
|
|
oib111 I post too much Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Thu Apr 02, 2009 10:22 pm Post subject: |
|
|
It works, you just have to select all and then hit solve.
_________________
8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
Back to top |
|
|
blackmorpheus Expert Cheater Reputation: 0
Joined: 05 Apr 2008 Posts: 159
|
Posted: Fri Apr 03, 2009 4:43 am Post subject: |
|
|
Thanks for sharing
|
|
Back to top |
|
|
haha01haha01 Grandmaster Cheater Supreme Reputation: 0
Joined: 15 Jun 2007 Posts: 1233 Location: http://www.SaviourFagFails.com/
|
Posted: Sat Apr 11, 2009 3:13 am Post subject: |
|
|
i found how to fix the bug mentioned above, you need to replace
Code: | if ((string)dataGridView1[i, j].Value == "") | with
Code: | if (dataGridView1[i,j].Value == null || (string)dataGridView1[i, j].Value == "") |
|
|
Back to top |
|
|
92Garfield I'm a spammer Reputation: 57
Joined: 20 Dec 2007 Posts: 5871 Location: Banana Republic Germany
|
Posted: Sun May 10, 2009 2:35 am Post subject: |
|
|
reupload, it's down and i'd like to test it
_________________
|
|
Back to top |
|
|
haha01haha01 Grandmaster Cheater Supreme Reputation: 0
Joined: 15 Jun 2007 Posts: 1233 Location: http://www.SaviourFagFails.com/
|
Posted: Sun May 10, 2009 1:21 pm Post subject: |
|
|
Reuploads (fixed the bug mentioned above):
Compiled Binary
Sauce
|
|
Back to top |
|
|
92Garfield I'm a spammer Reputation: 57
Joined: 20 Dec 2007 Posts: 5871 Location: Banana Republic Germany
|
Posted: Sun May 10, 2009 4:16 pm Post subject: |
|
|
Realy great job
_________________
|
|
Back to top |
|
|
clone Cheater Reputation: 0
Joined: 27 Jun 2006 Posts: 31
|
Posted: Thu Dec 17, 2009 12:19 am Post subject: |
|
|
Thanx..nice work
|
|
Back to top |
|
|
|