CEMETECH
Leading The Way To The Future
   
Login [Register]
Username:
Password:
Autologin:
Latest Headlines
Online Users
There are a total of 55 users online: 13 members, 21 guests and 21 bots.
Members: benryves, builderboy2005, calc84maniac, comicIDIOT, Hyped, KeithJohansen, KermMartian, LordConiupiter, souvik1997, TC01, TheStorm, WhiteValkery, _player1537.
Bots: Ask Jeeves (6), Googlebot (2), Yahoo! Slurp (2), EntireWeb (1), Baidu (5), Spinn3r (4), MSN/Bing (1).
RSS Feeds
[RSS] News Headlines
[RSS] Latest Posts
SAX
You must log in to view the SAX chat widget
Author Message
_player1537


Power User


Joined: 25 Nov 2009
Posts: 428

PostPosted: 02 Jan 2010 11:47:17 pm    Post subject: sodoku solving program Reply with quote

I am wanting to make a program that solves sodokus, but I don't know where to start (aside from the input of a sodoku, which I will work on later). What would be a good equation to put the correct numbers in the correct spots. I was thinking maybe make it figure out where a number could not go and then put in what's left, ie start with numbers 1-9 and check each row for numbers and get rid of that number in the list. Does that make sense and if it does would it work?
_________________
there are three kinds of people in this world, those who can count and those who can't.
there are 10 types of people in this world, those who understand binary and those who don't.




-Player
Back to top
View user's profile Send private message
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 31776
Location: Earth, Sol, Milky Way

PostPosted: 03 Jan 2010 12:49:29 am    Post subject: Reply with quote

The simplest Sudoku solves does no look-ahead/guessing. In other words, it searches each 3x3 square, and for each of the nine digits, checks if there's only one spot in that square where it can go. If so, it places it. It makes enough passes over the board to solve it completely. However, this can fail in some boards where you may need to do guessing and checking to properly solve the game. I think Tari may have made a solver (and others, since we had a Sudoku contest) somewhere.
_________________


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
_player1537


Power User


Joined: 25 Nov 2009
Posts: 428

PostPosted: 03 Jan 2010 01:05:59 am    Post subject: Reply with quote

thank you, I will try to work on one tonight. What do you think I should use to hold the sodoku problem while it is solving, a matrix or a string or list?
_________________
there are three kinds of people in this world, those who can count and those who can't.
there are 10 types of people in this world, those who understand binary and those who don't.




-Player
Back to top
View user's profile Send private message
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 31776
Location: Earth, Sol, Milky Way

PostPosted: 03 Jan 2010 01:08:52 am    Post subject: Reply with quote

Even though it's large, a matrix will be your best bet as far as simplicity of addressing. Smile Strings would be more efficient, but I bet the code to extract and insert digits would far defeat the efficiency in size of the data storage itself.
_________________


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
_player1537


Power User


Joined: 25 Nov 2009
Posts: 428

PostPosted: 03 Jan 2010 01:13:57 am    Post subject: Reply with quote

Quote:
The simplest Sudoku solves does no look-ahead/guessing. In other words, it searches each 3x3 square, and for each of the nine digits, checks if there's only one spot in that square where it can go. If so, it places it. It makes enough passes over the board to solve it completely. However, this can fail in some boards where you may need to do guessing and checking to properly solve the game. I think Tari may have made a solver (and others, since we had a Sudoku contest) somewhere.


could you maybe explain the method you said, it doesn't quite make sense to me?
_________________
there are three kinds of people in this world, those who can count and those who can't.
there are 10 types of people in this world, those who understand binary and those who don't.




-Player
Back to top
View user's profile Send private message
rthprog


Expert


Joined: 21 Sep 2007
Posts: 607
Location: relative to where?

PostPosted: 04 Jan 2010 07:38:42 am    Post subject: Reply with quote

_player1537 wrote:
Quote:
The simplest Sudoku solves does no look-ahead/guessing. In other words, it searches each 3x3 square, and for each of the nine digits, checks if there's only one spot in that square where it can go. If so, it places it. It makes enough passes over the board to solve it completely. However, this can fail in some boards where you may need to do guessing and checking to properly solve the game. I think Tari may have made a solver (and others, since we had a Sudoku contest) somewhere.


could you maybe explain the method you said, it doesn't quite make sense to me?


1) Look at a 3x3 square and determine what numbers have not been used in that square yet

2) Look at each empty slot (in the 3x3 square) and determine what numbers have not been used in it's row and column.
3) If there is only 1 common answer between steps 1 and 2, you have the number for the slot you were looking at.
4) repeat from step 2 until you have passed over every slot within the 3x3 square

5) repeat from step 1 (looking at the SAME square) until you have passed over every slot within the 3x3 square without making any changes (filling a slot)

6) repeat from step 1 (looking at a different 3x3 square) until you have passed over every 3x3 square without making any changes (filling a slot)
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 31776
Location: Earth, Sol, Milky Way

PostPosted: 04 Jan 2010 10:34:04 am    Post subject: Reply with quote

rthprog understood me perfectly. Smile This solution method is basically the same thing you do with your brain when you solve a sudoku puzzle. You look at each empty spot inside a given 3x3 square. As you know, each 3x3 square can contain only one each of digits 1-9. Therefore, each empty spot can only be whatever digits have no been used yet in that 3x3 square, which will have the same cardinality as the number of empty spots in the square. Next, you check the 1x9 row and the 9x1 column that contain the given spot, for each of the digits that remain in the 3x3 square, and if that digit is already somewhere in the row or column, it can't be in the given spot. If, after checking all possible digits for that spot, only one is not illegal, then that's the right answer, and you substitute that digit in that spot. Voila!
_________________


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
rthprog


Expert


Joined: 21 Sep 2007
Posts: 607
Location: relative to where?

PostPosted: 05 Jan 2010 07:40:43 am    Post subject: Reply with quote

...I'm wondering if it might possible to describe a sudoku problem as a (rather long) series of equations, and then use matrices to solve for the unknowns... the matrice would probably be too large to fit in ram, but if it indeed worked, it could be a significantly faster alternative to the method already described.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Komak57


Advanced Newbie


Joined: 24 Jun 2005
Posts: 64
Location: Lawrenceville

PostPosted: 05 Jan 2010 08:47:27 am    Post subject: reply Reply with quote

Although you might think it much, it would probably be good for you to design a sudoku app in order to understand how it works. Until then, heres some info that might come in handy.

To start, easy sudoku puzzles are easy to solve, as they have some plain-and-simple locations that you dont have to guess. harder sudoku puzzles give you half of those digits, so its mostly a guessing game. Technically speaking, you dont have to solve the entire sudoku puzzle to get your results. Only the center and corner pieces are mandatory. Less so the center. Solving 3/4 of the corner pieces will essentially have solved the puzzle. Simply design a randomiser to guess at the combination of 3 corners, and then to fill in the remaining pieces and check if its correct, on failure, try again.

examples...
Easy sudoku

expert...

you should first have it register the rows and collums each unchangable number is limited from.

1)Filling in the first square numerically would give you a limitation sequence like this...
(1,1: 8) (1,2: 6) (1,3: 1,3,4,6,9)
(2,1: 1,2,3,4,6,8) (2,2: 1,3,8) (2,3: 1,2,3,4,6,8,9)
(3,1: 1,2,3,4,5,6,7,9) (3,2: 1,3,5,7,8,9) (3,3: 1,2,3,4,6,8,9)
2)next it would clear all stationary numbers from the list.. in this case 8 and 6
(1,1: 8) (1,2: 6) (1,3: 1,3,4,9)
(2,1: 1,2,3,4) (2,2: 1,3) (2,3: 1,2,3,4,9)
(3,1: 1,2,3,4,5,7,9) (3,2: 1,3,5,7,9) (3,3: 1,2,3,4,9)
3)now it generates any numbers that cant fit elsewhere
86?,???,???
4)then fills in digits in numerical order in all possible combinations
1: 861,234,579
2: 863,214,579
3: 864,231,579
for smaller explanation, ill keep the solutions to 3... btw, 2 cannot be replaced by 1 in 1,3...

Next corner
keep in mind, this will only read numbers already provided
step1)
(1,1: 1,2,3,4,5,7,9) (1,2: 1,2,3,4,7,9) (1,3: 1,2,3,4,5)
(2,1: 1,2,3,4,7) (2,2: 5) (2,3: 9)
(3,1: 1,2,3,4,5,7,9) (3,2: 1,2,3,4,6,7,8,9) (3,3: 1,2,3,4,5,6,8)
step2)
(1,1: 1,2,3,4,7) (1,2: 1,2,3,4,7) (1,3: 1,2,3,4)
(2,1: 1,2,3,4,7) (2,2: 5) (2,3: 9)
(3,1: 1,2,3,4,7) (3,2: 1,2,3,4,6,7,8) (3,3: 1,2,3,4,6,8)
step3)
???,?59,???
step4)
1: 123,459,768
2: 213,459,768
3: 321,459,768

after you get all 4 corners done (though you could do this for all 9 squares) you can do 2 things. 1, try to fit combination block 1,1:1 (top left combo 1) with 1,2:1 (top middle combo 1) and cycle through till one fits, then continue to 3 until it locks up (unable to find a combination, and continue with 1,1:2 until all squares fit, or have it manually continue to do a more complicated version of step 1-4...
for an exampe, combo 1,1:1 doesnt fit with 1,2:1 due to digit 1 being in first slot and would cycle through until 1 wasnt in the first column, and since there are no combinations listed (yeah, i made it smaller on purpose) would try 1,1:2 with 1,2:1... 3 doesnt fit and would eventually lock up because there are no listed combinations... causing it to attempt 1,1:3 with 1,2:1 and 7 (and 9) dont fit... because of the limit of 3 combinations, this example would fail... but continue on, it would eventually come out with the solution.

good luck coding it
_________________
Foxes Rule our World...

Koware Technologies current projects:
[v0.0.2]-DS C++(MapleStory DS)

v[playability].[working functions].[progress 0-9]
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
rthprog


Expert


Joined: 21 Sep 2007
Posts: 607
Location: relative to where?

PostPosted: 05 Jan 2010 09:49:26 am    Post subject: Re: reply Reply with quote

Komak57 wrote:
harder sudoku puzzles give you half of those digits, so its mostly a guessing game. Technically speaking, you dont have to solve the entire sudoku puzzle to get your results. Only the center and corner pieces are mandatory. Less so the center. Solving 3/4 of the corner pieces will essentially have solved the puzzle. Simply design a randomiser to guess at the combination of 3 corners, and then to fill in the remaining pieces and check if its correct, on failure, try again.


but there are problems with brute force.
1) Generally, somewhat slow...
2) If you're just guessing on some parts, you'll waste time completing "solutions" which are wrong

I would say that it would be best to
1) employ Kerm's method to solve as much as possible based on logic (which should complete most of the puzzle, if not all)
2) Use guessing to fill in a few slots, and then see if Kerm's method can solve it. If not, revert back to the matrice generated in step 1, and try a different guess.

This way, the guessing will only occur when you have a few empty positions, greatly reducing the time needed to check if that is a solution, as well as the number of potential solutions.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Komak57


Advanced Newbie


Joined: 24 Jun 2005
Posts: 64
Location: Lawrenceville

PostPosted: 05 Jan 2010 11:05:36 am    Post subject: Reply with quote

you might wanna re-check my process... the only way doing a process of elimination would work is if you were playing easy mode... which gives you 2~5 answers to each block... with my provided modification to Kerms method essentially DOES use elimination when and where possible. But again, in expert, you only get about 2 answers per block, and solving it yourself, theres a LOT of guesswork... the only faster way to solving it would be to have every possible configuration listed in an array/matrix and find the one that matches... which would still take forever depending on how far down the list it is...

with the above method, it would only take a few seconds to get all the combinations of 1 block, multiply that by 9, and then account for the cycling of combinations... it would take maybe 5~10 minutes at most. depends on the processor and what language its written in to how fast it really goes... i can immagine with an adequate 2ghz processor and something like C++ or other 'clean' language it would take an average of 2 minutes per expert puzzle
_________________
Foxes Rule our World...

Koware Technologies current projects:
[v0.0.2]-DS C++(MapleStory DS)

v[playability].[working functions].[progress 0-9]
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 31776
Location: Earth, Sol, Milky Way

PostPosted: 05 Jan 2010 11:37:42 am    Post subject: Reply with quote

Yup, my method does indeed fail on medium or hard puzzles, due to the need to do lookahead guesswork. Very impressive post there, Komak.
_________________


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
_player1537


Power User


Joined: 25 Nov 2009
Posts: 428

PostPosted: 05 Jan 2010 05:29:19 pm    Post subject: Reply with quote

Thank you Komak, I just have two questions: what does" Cool " mean and how do you define your locations, like if you said (1,2) what point on the sodoku are you talking about? Other than that, I agree, your post was really good Smile

btw, I am programming this on my calculator (ti-84+ silver edition) in Ti-Basic, I will maybe port it to something faster if I make a working version.
_________________
there are three kinds of people in this world, those who can count and those who can't.
there are 10 types of people in this world, those who understand binary and those who don't.




-Player
Back to top
View user's profile Send private message
rthprog


Expert


Joined: 21 Sep 2007
Posts: 607
Location: relative to where?

PostPosted: 05 Jan 2010 05:59:29 pm    Post subject: Reply with quote

_player1537 wrote:
Thank you Komak, I just have two questions: what does" Cool " mean and how do you define your locations, like if you said (1,2) what point on the sodoku are you talking about? Other than that, I agree, your post was really good Smile

btw, I am programming this on my calculator (ti-84+ silver edition) in Ti-Basic, I will maybe port it to something faster if I make a working version.


Cool means "8)", it's just that cemetech recognizes "8)" as a smiley
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
steelersfan1693


Member


Joined: 05 Dec 2008
Posts: 163
Location: footballfanatics.fforum.biz

PostPosted: 06 Jan 2010 10:54:31 am    Post subject: Reply with quote

hehehehe
Back to top
View user's profile Send private message Send e-mail AIM Address
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 31776
Location: Earth, Sol, Milky Way

PostPosted: 06 Jan 2010 10:59:54 am    Post subject: Reply with quote

_player1537 wrote:
Thank you Komak, I just have two questions: what does" Cool " mean and how do you define your locations, like if you said (1,2) what point on the sodoku are you talking about? Other than that, I agree, your post was really good Smile

btw, I am programming this on my calculator (ti-84+ silver edition) in Ti-Basic, I will maybe port it to something faster if I make a working version.
In normal matrix notation, you write coordinates as (row, column), so (1,2) would refer to the second column in the first row. I disabled smilies in Komak's post so that 8 ) shows up as Cool.
_________________


Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
_player1537


Power User


Joined: 25 Nov 2009
Posts: 428

PostPosted: 07 Jan 2010 10:06:00 pm    Post subject: Reply with quote

thank you Kerm, I have written the modules that check what numbers have not been used by the 3x3 square and the rows and columns too. Then it checks which numbers match between them all. Finally it checks if any of the numbers match, and if there is only one answer, it places it. Smile should be done soon
_________________
there are three kinds of people in this world, those who can count and those who can't.
there are 10 types of people in this world, those who understand binary and those who don't.




-Player
Back to top
View user's profile Send private message
Komak57


Advanced Newbie


Joined: 24 Jun 2005
Posts: 64
Location: Lawrenceville

PostPosted: 09 Jan 2010 09:21:16 pm    Post subject: matricies Reply with quote

Keep in mind that there are multiple possibilities for each block (9 squares per block, 9 blocks per puzzle)... the answer cant be found until you have ruled out more variants in multiple matrices. It may take quite a few matrices to find out the right combination... In my above matrix, you would end up with 9 matrices holding a maximum of 9^9! = 362880 (9^9 = 387420489, permutation (non repeating numbers) = 362880). multiply by 9 means 3265920 total variables will be saved between all 9 matrices.. a TI calculator would be incapable of this formula. this is a maximum though, which ignores the fact that 2 numbers are givin immediately, and more for easier difficulties. I hope your using a 'clean' code, or this will take some time to decipher it.

you can find a lot more math on the subject with some good ol documentation from wikipedia here : http://en.wikipedia.org/wiki/Mathematics_of_Sudoku

I could be a bit more helpful if i knew the base language you were using (basic, C, assembly etc) My programming talent is the ability to translate any code into another code i know.
_________________
Foxes Rule our World...

Koware Technologies current projects:
[v0.0.2]-DS C++(MapleStory DS)

v[playability].[working functions].[progress 0-9]
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address MSN Messenger
_player1537


Power User


Joined: 25 Nov 2009
Posts: 428

PostPosted: 09 Jan 2010 10:51:28 pm    Post subject: Reply with quote

ti-basic, I will look at that website in a minute.
_________________
there are three kinds of people in this world, those who can count and those who can't.
there are 10 types of people in this world, those who understand binary and those who don't.




-Player
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Forum powered by phpBB

© Copyright 2000-2010 Cemetech & Kerm Martian :: Page Execution Time: 0.108990 seconds.