Sudoku Solver - Сообщения
Actually it is a C code which I am trying to implicate to SMath. C code is also included and runs perfectly.
In SMath, code works to a point actually. When I debug it I can see it can assign numbers, backtrack if there is no option.
So SMath code also seems legit but eventually the algorithm just stop working. No error no significant reason.
With different puzzles, code terminated at different places at middle of calculation.
I couldn't figure out what is wrong. Is it a bug or my coding is insufficient?
Any help should be appreciated.
Regards.
sudoku.sm (26 КиБ) скачан 61 раз(а).
sudoku.7z (38 КиБ) скачан 32 раз(а).
WroteI posted something very inaccurate before and have since deleted it. However, in my testing, it seems that it's not dependent on the number of iterations. The function seems to stop when rw,cl get to around 2,4 or 2,5. This is independent of the number of function calls to fillSudoku.
This looks to correlate to a depth of ~21 or 22 levels of recursion no matter the starting puzzle.
Wrote... your original creates "critical error", that can be repaired in the first module.
Sudoku First Module.sm (17 КиБ) скачан 34 раз(а).
from the code you imitate. As corrected, red.
Red may mean not winning ?
sudoku Freak.sm (23 КиБ) скачан 35 раз(а).
WroteWroteI posted something very inaccurate before and have since deleted it. However, in my testing, it seems that it's not dependent on the number of iterations. The function seems to stop when rw,cl get to around 2,4 or 2,5. This is independent of the number of function calls to fillSudoku.
This looks to correlate to a depth of ~21 or 22 levels of recursion no matter the starting puzzle.
To better illustrate what I think is happening I've created the following worksheet. The first function definition is just a simple function that calls itself recursively until its 200th call at which point it exits. However, when run it experiences the same error as we see in the sudoku.sm. I rewrote the function using a try/on error and we see we only get to 50 iterations before it fails.
recursion.sm (4 КиБ) скачан 29 раз(а).
WroteThis looks to correlate to a depth of ~21 or 22 levels of recursion no matter the starting puzzle.
Wrote
To better illustrate what I think is happening I've created the following worksheet. The first function definition is just a simple function that calls itself recursively until its 200th call at which point it exits. However, when run it experiences the same error as we see in the sudoku.sm. I rewrote the function using a try/on error and we see we only get to 50 iterations before it fails.
recursion.sm (4 КиБ) скачан 29 раз(а).
What I understood considering your last messages, you think there is nothing significant wrong with the code itself. Problem is SMath handling of recursions.
So, it comes forward that is why I wouldn't be able to make an SMath Sudoku Solver with recursion.
Thank you Alyles.
WroteWroteThis looks to correlate to a depth of ~21 or 22 levels of recursion no matter the starting puzzle.
Wrote
To better illustrate what I think is happening I've created the following worksheet. The first function definition is just a simple function that calls itself recursively until its 200th call at which point it exits. However, when run it experiences the same error as we see in the sudoku.sm. I rewrote the function using a try/on error and we see we only get to 50 iterations before it fails.
recursion.sm (4 КиБ) скачан 29 раз(а).
What I understood considering your last messages, you think there is nothing significant wrong with the code itself. Problem is SMath handling of recursions.
So, it comes forward that I wouldn't be able to make an SMath Sudoku Solver.
Thank you Alyles.
I remember this limitation was introduced some time ago to avoid unintentional hard crashes on wrong formed algorithms; considering that any recursive algorithm can be made iterative, you probably have to design it in another way or find a different code


It may be slow, but it works. Might be able to optimize for better performance.
sudoku_lyles2.sm (28 КиБ) скачан 36 раз(а).
WroteAs Davide said, you don't have to do it recursively.
It may be slow, but it works. Might be able to optimize for better performance.
sudoku_lyles2.sm (28 КиБ) скачан 36 раз(а).
Well it works for the first two puzzles at least. Having issues with the third. Haven't tried the fourth....
It's a start
Wrote
Well it works for the first two puzzles at least. Having issues with the third. Haven't tried the fourth....
It works for the fourth, but fails for the third puzzle.
WroteI remember this limitation was introduced some time ago to avoid unintentional hard crashes on wrong formed algorithms; considering that any recursive algorithm can be made iterative, you probably have to design it in another way or find a different code
![]()
Wow, I didn't know there is a purposed limitation for recursion. For those who knows what they are doing, I think that limit can be removed by adding an extra code at the beginning like (recurselimit:=0), or re-adding the limit (recurselimit:=1).
Yeah it can be made iterative, alyles already did one as far as I can see. I just wanted you guys to check if I did something wrong about my algorithm. I just love recursing, I always feel like it is magical to me.

Thank you all guys, regards
WroteWrote
Well it works for the first two puzzles at least. Having issues with the third. Haven't tried the fourth....
It works for the fourth, but fails for the third puzzle.
Don't bother about it. I found these sudoku's on internet without checking them.
I checked that puzzle with C code right now and it has no solution.
Regards
Wrote
Wow, I didn't know there is a purposed limitation for recursion. For those who knows what they are doing, I think that limit can be removed by adding an extra code at the beginning like (recurselimit:=0), or re-adding the limit (recurselimit:=1).
Hi. It exists in other languages. For instance, can see it at https://reference.wolfram.com/language/ref/$RecursionLimit.html
Best regards.
Alvaro.
WroteDon't bother about it. I found these sudoku's on internet without checking them.
I checked that puzzle with C code right now and it has no solution.
You mean puzzle 3 has no solution ?
Solution is => give to champions.
Attached utilities may be useful otherwise.
Mathemtica 4.0 "recursion limit" is pure jargon.
In some program, if/otherwise does not work [if/else = YES].
Is there a catch wrt puzzle 3 ... Watson ?
Utilities Matrix Count in Soduku.sm (22 КиБ) скачан 33 раз(а).
SudokuRec.zip (24 КиБ) скачан 27 раз(а).
SudokuRec.pdf (285 КиБ) скачан 29 раз(а).
This other is te recurrent version in SMath: don't works.
SudokuRec.sm (45 КиБ) скачан 32 раз(а).
This other is a rewrite of the alyles version.
SudokuBruteForce_lyles.sm (43 КиБ) скачан 47 раз(а).
Best regards.
Alvaro.
-
Новые сообщения
-
Нет новых сообщений