![]() |
| ||
| soduko problem hi guys , I am interested in writing a code to do the soduko ( or sudoku ) , I found this code on the internet which is supposed to be the shortest soduko solver but it is so short that I can not undrestand it . can any one help please ? def r(a): i=a.find('0') if i<0:print a [m in[(i-j)%9*(i/9^j/9)*(i/27^j/27|i%9/3^j%9/3)or a[j]forj in range(81)]or r(a[:i]+m+a[i+1:])for m in`14**7*9`]r(raw_input())thanx in advanceali |
| ||
| Re: soduko problem hi, Quote:
Quote:
kath. |
| ||
| Re: soduko problem this is how it was written on the internet , all in one line , I just paste and copied it |
| ||
| Re: soduko problem There are basically two ways to solve a sudoku: 1) Solve it by logic, using simple rules such as the ones we, human beings, use, such as "if a square has only one possibility, than that number must be there". There are several solvers on the net that implement this kind of deductive solving, and reading the way they do it can probably give you an idea of what to do: http://www.sudokusolver.co.uk/solvemethods.html http://www.gwerdy.com/products/sudoku_solver/ 2) Backtracking. Basically, using this method, you try every possible solution; if you reach a dead-end, you backtrack one square and try another number instead of the last number you tried. Googling for "sudoku solver" often reveals many pages about Donald Knuth's DLX algorithm, but I think something like that is better left to C. |
| ||
| Re: soduko problem thanks , those links could be helpful . I have not read them yet |
| ||
| Re: soduko problem Request: Quote:
Quote:
|
| ||
| Re: soduko problem hi BearofNH , I did not mean to make excuses , the code looked pretty strange to me , this is how I figured it should be with proper indentation : def r(a):this is the best I could come up with and if it helps , this is how to run it : echo 000010000301400860900500200700160000020805010000097004003004006048006907000080000 | python sudoku.py one of the many things which I don't undrestand is the '14**7*9' , I hope I have been helpful . sorry for not doing this earlier ali |
| ||
| Re: soduko problem #solve sudoku by backtracking |
| ||
| Re: soduko problem hi ffao , thank you very much , now I undrestand what is going on . thanks again ali |
| All times are GMT -4. The time now is 7:32 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC