View previous topic :: View next topic |
Author |
Message |
| Lunatic
| Joined: 11 Mar 2007 | Posts: 166 | : | Location: Ghent - Belgium | Items |
|
Posted: Fri Nov 21, 2008 11:36 pm Post subject: View/download C code for Random Sudoku Generator |
|
|
For anyone interrested, i've translated my VisualBasic code from my own sudoku generator to C code. It's a stripped down version who just generates a random solution and then turns it into an 180° rotational Sudoku with one unique solution.
The code can be viewed/downloaded with this URL:
http://users.pandora.be/mpq/sudoku/random_sudoku_generator.c _________________ Marc
~~~<><~~~<><~~~<><~~~<><~~~ |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Wed Dec 10, 2008 7:39 am Post subject: |
|
|
Why used naked single and not hidden single ?
from my experience, hidden singles and brute force are enough to solve any puzzle in reasonable amount of time
and, i loop indefinitely removing clues when generating random puzzles :lol: |
|
Back to top |
|
|
| Lunatic
| Joined: 11 Mar 2007 | Posts: 166 | : | Location: Ghent - Belgium | Items |
|
Posted: Wed Dec 10, 2008 11:28 am Post subject: |
|
|
cardinal wrote: | Why used naked single and not hidden single ? |
The way i wrote the code, happens to be easier to spot naked singles, rather than hidden singles. I did tried hidden singles, but it slowed down the overall performance. One could use more/better bitwise arrays to make it easier to spot hidden singles to gain speed. The code i published is merely an example, anyone may use it and/or improve it. _________________ Marc
~~~<><~~~<><~~~<><~~~<><~~~ |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Wed Dec 10, 2008 8:48 pm Post subject: |
|
|
yes you are right. the speed is important :)
try this animal :
.........
.4.......
...6..8..
...9.....
.....85..
...2.....
.......34
.69....2.
2.......6 |
|
Back to top |
|
|
| tarek
| Joined: 31 Dec 2005 | Posts: 153 | : | Location: London, UK | Items |
|
Posted: Wed Dec 10, 2008 9:00 pm Post subject: |
|
|
cardinal wrote: | try this animal :
.........
.4.......
...6..8..
...9.....
.....85..
...2.....
.......34
.69....2.
2.......6 | That animal has no 1s & no 7s
tarek |
|
Back to top |
|
|
| Lunatic
| Joined: 11 Mar 2007 | Posts: 166 | : | Location: Ghent - Belgium | Items |
|
Posted: Wed Dec 10, 2008 10:10 pm Post subject: |
|
|
cardinal wrote: | yes you are right. the speed is important
try this animal :
.........
.4.......
...6..8..
...9.....
.....85..
...2.....
.......34
.69....2.
2.......6 |
My code is the code for a generator, not a uniqueness tester/solver. However, there's a uniqueness tester implemented, so you can easely transform it into a tester. _________________ Marc
~~~<><~~~<><~~~<><~~~<><~~~ |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Thu Dec 11, 2008 12:20 am Post subject: |
|
|
when i'm trying to make a truly random generator, i step into some bad situations :lol:
for example, solving top 1465 is no problem, but randomness, is different thing, because strange puzzles appear
tarek, is there some rule that says something about too many missing digits ? because i'd like some inside information |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Thu Dec 11, 2008 1:37 am Post subject: |
|
|
here's another dangerous animal :
...6...7.
...4.5...
...7.....
9.....5..
...5.7...
....4....
65....417
.4.......
.........
this one blocks sudocue for 2-3 seconds |
|
Back to top |
|
|
| m_b_metcalf
| Joined: 13 Mar 2006 | Posts: 210 | : | Location: Berlin | Items |
|
Posted: Thu Dec 11, 2008 6:19 am Post subject: |
|
|
cardinal wrote: |
is there some rule that says something about too many missing digits ? because i'd like some inside information. |
A valid sudoku's clues must contain at least 8 distinct values, otherwise it certainly has multiple values. Consider a puzzle with no 8s and no 9s. In any solution grid it will be possible to interchange all the 8s with all the 9s, producing a second solution independent of the initial clues.
Regards,
Mike Metcalf |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Thu Dec 11, 2008 7:24 am Post subject: |
|
|
thank you, but also it can have no solution :)
so, i have to backtrack it anyway :( to tell if has multiple or no solution
or there is a faster way ? |
|
Back to top |
|
|
| m_b_metcalf
| Joined: 13 Mar 2006 | Posts: 210 | : | Location: Berlin | Items |
|
Posted: Thu Dec 11, 2008 8:20 am Post subject: |
|
|
cardinal wrote: | thank you, but also it can have no solution
so, i have to backtrack it anyway to tell if has multiple or no solution
or there is a faster way ? |
Yes.
1) If, in any row/column/box, a given value appears neither as a clue nor as a candidate, the puzzle has no solution.
2) If, in any cell, there is neither a clue nor a candidate, the puzzle has zero solutions.
3) If, in any cell, n (n > 1) values appear and they appear only once in the row/column/box, then they are competing for that cell implying a deadlock and so zero solutions. (Limiting to n to 2 covers the vast majority of cases.)
For multiple solutions, yes you have to count, but you can stop the count at two.
HTH
Mike Metcalf |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Thu Dec 11, 2008 1:53 pm Post subject: |
|
|
......3..
....3.4.6
......2..
...5..6..
.4.......
.7...9...
...19....
126.83...
......... |
|
Back to top |
|
|
| m_b_metcalf
| Joined: 13 Mar 2006 | Posts: 210 | : | Location: Berlin | Items |
|
Posted: Thu Dec 11, 2008 2:59 pm Post subject: |
|
|
cardinal wrote: | ......3..
....3.4.6
......2..
...5..6..
.4.......
.7...9...
...19....
126.83...
......... |
Please don't post on both the Players' and the Programmers' Fora.
Thanks,
Mike Metcalf |
|
Back to top |
|
|
| cardinal
| Joined: 08 Apr 2006 | Posts: 40 | : | | Items |
|
Posted: Thu Dec 11, 2008 3:14 pm Post subject: |
|
|
huh ? why ?
OK, if you say so :D
what about the puzzle ? you still need to backtrack it or you know an easy way out ?
thx |
|
Back to top |
|
|
| hobiwan
| Joined: 11 Feb 2008 | Posts: 83 | : | | Items |
|
Posted: Fri Dec 12, 2008 6:26 am Post subject: |
|
|
m_b_metcalf wrote: | Please don't post on both the Players' and the Programmers' Fora. |
cardinal wrote: | huh ? why ? |
Because many people follow both forums. And just for clarity: Please don't post the same puzzle on both forums. |
|
Back to top |
|
|
|