For the rainy autumn days to come ;-)performance.
A few years ago there were some discussions and somewhat complicated program concepts here on c.l.f for solving Sudoku puzzles. I wondered if the Forth CLP methods developed for the Hexagon puzzle could be applied to Sudokus as well to improve
Recently I came across a puzzle that claimed to be particularly difficult to solve using backtracking methods. So it can be used as benchmark. It took about 1s to solve with Prolog on my old laptop, which is quite slow indeed. Can Forth do better?
The puzzle is:
_,_,_, _,_,_, _,_,_,
_,_,_, _,_,3, _,8,5,
_,_,1, _,2,_, _,_,_,
_,_,_, 5,_,7, _,_,_,
_,_,4, _,_,_, 1,_,_,
_,9,_, _,_,_, _,_,_,
5,_,_, _,_,_, _,7,3,
_,_,2, _,1,_, _,_,_,
_,_,_, _,4,_, _,_,9
Another hard one:
8,_,_, _,_,_, _,_,_,
_,_,3, 6,_,_, _,_,_,
_,7,_, _,9,_, 2,_,_,
_,5,_, _,_,7, _,_,_,
_,_,_, _,4,5, 7,_,_,
_,_,_, 1,_,_, _,3,_,
_,_,1, _,_,_, _,6,8,
_,_,8, 5,_,_, _,1,_,
_,9,_, _,_,_, 4,_,_
On Monday, 16 October 2023 at 10:20:16 UTC+2, minforth wrote:performance.
For the rainy autumn days to come ;-)
A few years ago there were some discussions and somewhat complicated program concepts here on c.l.f for solving Sudoku puzzles. I wondered if the Forth CLP methods developed for the Hexagon puzzle could be applied to Sudokus as well to improve
Recently I came across a puzzle that claimed to be particularly difficult to solve using backtracking methods. So it can be used as benchmark. It took about 1s to solve with Prolog on my old laptop, which is quite slow indeed. Can Forth do better?
It took me 11min 26sec to solve it with my head!, without using backtracking. So Prolog is almost 700 times faster then me ;-)
I've had a sudoku solver in my repository since 2005 (Version: 1900 01092005 - Robert Spykerman)It took me 11min 26sec to solve it with my head!, without using backtracking. So Prolog is almost 700 times faster then me ;-):-) Congratulations!
I read that the first puzzle had been designed to stress simple backtracking solvers.
Concerning the second puzzle it was said that it is hard for humans.
On Monday, October 16, 2023 at 11:33:36 AM UTC+2, minforth wrote:
It took me 11min 26sec to solve it with my head!, without using backtracking. So Prolog is almost 700 times faster then me ;-):-) Congratulations!
I read that the first puzzle had been designed to stress simple backtracking solvers.I've had a sudoku solver in my repository since 2005 (Version: 1900 01092005 - Robert Spykerman)
Concerning the second puzzle it was said that it is hard for humans.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/sudoku.4th
It solved the second one in 0s flat:
8 1 2 | 7 5 3 | 6 4 9
9 4 3 | 6 8 2 | 1 7 5
6 7 5 | 4 9 1 | 2 8 3
------+-------+------
1 5 4 | 2 3 7 | 8 9 6
3 6 9 | 8 4 5 | 7 2 1
2 8 7 | 1 6 9 | 5 3 4
------+-------+------
5 2 1 | 9 7 4 | 3 6 8
4 3 8 | 5 2 6 | 9 1 7
7 9 6 | 3 1 8 | 4 5 2
The first one - a tiny delay (let's say a second):
9 8 7 | 6 5 4 | 3 2 1
2 4 6 | 1 7 3 | 9 8 5
3 5 1 | 9 2 8 | 7 4 6
------+-------+------
1 2 8 | 5 3 7 | 6 9 4
6 3 4 | 8 9 2 | 1 5 7
7 9 5 | 4 6 1 | 8 3 2
------+-------+------
5 1 9 | 2 8 6 | 4 7 3
4 7 2 | 3 1 9 | 5 6 8
8 6 3 | 7 4 5 | 2 1 9
The second one perhaps just demonstrates that a computer can hold more variables
in his memory than most human beings in their mind. See https://abcnews.go.com/blogs/headlines/2012/06/can-you-solve-the-hardest-ever-sudoku
For the rainy autumn days to come ;-)
Recently I came across a puzzle that claimed to be particularly difficult to solve using backtracking
methods. So it can be used as benchmark. It took about 1s to solve with Prolog on my old laptop,
which is quite slow indeed. Can Forth do better?
The puzzle is:
_,_,_, _,_,_, _,_,_,
_,_,_, _,_,3, _,8,5,
_,_,1, _,2,_, _,_,_,
_,_,_, 5,_,7, _,_,_,
_,_,4, _,_,_, 1,_,_,
_,9,_, _,_,_, _,_,_,
5,_,_, _,_,_, _,7,3,
_,_,2, _,1,_, _,_,_,
_,_,_, _,4,_, _,_,9
Another hard one:
8,_,_, _,_,_, _,_,_,
_,_,3, 6,_,_, _,_,_,
_,7,_, _,9,_, 2,_,_,
_,5,_, _,_,7, _,_,_,
_,_,_, _,4,5, 7,_,_,
_,_,_, 1,_,_, _,3,_,
_,_,1, _,_,_, _,6,8,
_,_,8, 5,_,_, _,1,_,
_,9,_, _,_,_, 4,_,_
On Monday, October 16, 2023 at 10:20:16 AM UTC+2, minforth wrote:
For the rainy autumn days to come ;-)One second? How old is that laptop?
Recently I came across a puzzle that claimed to be particularly difficult to solve using backtracking
methods. So it can be used as benchmark. It took about 1s to solve with Prolog on my old laptop,
which is quite slow indeed. Can Forth do better?
Hans Bezemer schrieb am Montag, 16. Oktober 2023 um 16:16:33 UTC+2:
On Monday, October 16, 2023 at 11:33:36 AM UTC+2, minforth wrote:
It took me 11min 26sec to solve it with my head!, without using backtracking. So Prolog is almost 700 times faster then me ;-):-) Congratulations!
I read that the first puzzle had been designed to stress simple backtracking solvers.I've had a sudoku solver in my repository since 2005 (Version: 1900 01092005 - Robert Spykerman)
Concerning the second puzzle it was said that it is hard for humans.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/sudoku.4th
It solved the second one in 0s flat:
8 1 2 | 7 5 3 | 6 4 9
9 4 3 | 6 8 2 | 1 7 5
6 7 5 | 4 9 1 | 2 8 3
------+-------+------
1 5 4 | 2 3 7 | 8 9 6
3 6 9 | 8 4 5 | 7 2 1
2 8 7 | 1 6 9 | 5 3 4
------+-------+------
5 2 1 | 9 7 4 | 3 6 8
4 3 8 | 5 2 6 | 9 1 7
7 9 6 | 3 1 8 | 4 5 2
The first one - a tiny delay (let's say a second):
9 8 7 | 6 5 4 | 3 2 1
2 4 6 | 1 7 3 | 9 8 5
3 5 1 | 9 2 8 | 7 4 6
------+-------+------
1 2 8 | 5 3 7 | 6 9 4
6 3 4 | 8 9 2 | 1 5 7
7 9 5 | 4 6 1 | 8 3 2
------+-------+------
5 1 9 | 2 8 6 | 4 7 3
4 7 2 | 3 1 9 | 5 6 8
8 6 3 | 7 4 5 | 2 1 9
The first one looks like a synthetic exercise made up only as backtracking benchmark.
Look at the first row. So it is perhaps easier to solve with non-backtracking methods.
minforth schrieb am Montag, 16. Oktober 2023 um 16:35:36 UTC+2:
Hans Bezemer schrieb am Montag, 16. Oktober 2023 um 16:16:33 UTC+2:backtracking benchmark.
On Monday, October 16, 2023 at 11:33:36 AM UTC+2, minforth wrote:The first one looks like a synthetic exercise made up only as
I've had a sudoku solver in my repository since 2005 (Version: 1900 >01092005 - Robert Spykerman)It took me 11min 26sec to solve it with my head!, without using >backtracking. So Prolog is almost 700 times faster then me ;-):-) Congratulations!
I read that the first puzzle had been designed to stress simple >backtracking solvers.
Concerning the second puzzle it was said that it is hard for humans.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/sudoku.4th
It solved the second one in 0s flat:
8 1 2 | 7 5 3 | 6 4 9
9 4 3 | 6 8 2 | 1 7 5
6 7 5 | 4 9 1 | 2 8 3
------+-------+------
1 5 4 | 2 3 7 | 8 9 6
3 6 9 | 8 4 5 | 7 2 1
2 8 7 | 1 6 9 | 5 3 4
------+-------+------
5 2 1 | 9 7 4 | 3 6 8
4 3 8 | 5 2 6 | 9 1 7
7 9 6 | 3 1 8 | 4 5 2
The first one - a tiny delay (let's say a second):
9 8 7 | 6 5 4 | 3 2 1
2 4 6 | 1 7 3 | 9 8 5
3 5 1 | 9 2 8 | 7 4 6
------+-------+------
1 2 8 | 5 3 7 | 6 9 4
6 3 4 | 8 9 2 | 1 5 7
7 9 5 | 4 6 1 | 8 3 2
------+-------+------
5 1 9 | 2 8 6 | 4 7 3
4 7 2 | 3 1 9 | 5 6 8
8 6 3 | 7 4 5 | 2 1 9
Look at the first row. So it is perhaps easier to solve with >non-backtracking methods.
Sudokus can be rotated by n x 90 degrees, rows/columns 1-3 or 4-6 or 7-9 can be
swapped, without destroying solvability.
Such symmetries could be used to precondition the matrix for a speedier >solver (less backtracking).
Don't ask if it is worth it. ;-) It is only a game.
In article <e1bb7bd8-2195-4cea...@googlegroups.com>,
minforth <minf...@arcor.de> wrote:
minforth schrieb am Montag, 16. Oktober 2023 um 16:35:36 UTC+2:
Hans Bezemer schrieb am Montag, 16. Oktober 2023 um 16:16:33 UTC+2:
On Monday, October 16, 2023 at 11:33:36 AM UTC+2, minforth wrote:The first one looks like a synthetic exercise made up only as >backtracking benchmark.
https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/4th.src/sudoku.4thIt took me 11min 26sec to solve it with my head!, without using >backtracking. So Prolog is almost 700 times faster then me ;-):-) Congratulations!
I read that the first puzzle had been designed to stress simple >backtracking solvers.
Concerning the second puzzle it was said that it is hard for humans. >> > I've had a sudoku solver in my repository since 2005 (Version: 1900 >01092005 - Robert Spykerman)
It solved the second one in 0s flat:
8 1 2 | 7 5 3 | 6 4 9
9 4 3 | 6 8 2 | 1 7 5
6 7 5 | 4 9 1 | 2 8 3
------+-------+------
1 5 4 | 2 3 7 | 8 9 6
3 6 9 | 8 4 5 | 7 2 1
2 8 7 | 1 6 9 | 5 3 4
------+-------+------
5 2 1 | 9 7 4 | 3 6 8
4 3 8 | 5 2 6 | 9 1 7
7 9 6 | 3 1 8 | 4 5 2
The first one - a tiny delay (let's say a second):
9 8 7 | 6 5 4 | 3 2 1
2 4 6 | 1 7 3 | 9 8 5
3 5 1 | 9 2 8 | 7 4 6
------+-------+------
1 2 8 | 5 3 7 | 6 9 4
6 3 4 | 8 9 2 | 1 5 7
7 9 5 | 4 6 1 | 8 3 2
------+-------+------
5 1 9 | 2 8 6 | 4 7 3
4 7 2 | 3 1 9 | 5 6 8
8 6 3 | 7 4 5 | 2 1 9
Look at the first row. So it is perhaps easier to solve with >non-backtracking methods.
Sudokus can be rotated by n x 90 degrees, rows/columns 1-3 or 4-6 or 7-9 can be
swapped, without destroying solvability.
Such symmetries could be used to precondition the matrix for a speedier >solver (less backtracking).
Don't ask if it is worth it. ;-) It is only a game.
I sort the fields to be probed once in the beginning, on the
remaining possibilities of the content. This order is relevant
throughout.
It is remarkable that the second sudoku is much harder in my book also.
28 ms versus 180 ms on my 4 Ghz AMD system.
(11 versus 75 if I kill mprime that is running on 8 cores.).
It is remarkable that Marcel Hendrix solved the second soduku
substantially faster than the first. Is that an error?
The majority of Marcel's timings were in the sub-milliseconds range,
while some puzzles took substantially longer. I wondered if this "discrepancy" was caused by where in the matrix the algorithm started.
The majority of Marcel's timings were in the sub-milliseconds range,
while some puzzles took substantially longer. I wondered if this "discrepancy" was caused by where in the matrix the algorithm started.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 20:04:12 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,093 |