Sudoku Programmers Forum Index

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in          Games  Calendar

Log in to check your private messagesLog in to check your private messages   

View/download C code for Random Sudoku Generator

 
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku
View previous topic :: View next topic  
Author Message
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Fri Nov 21, 2008 11:36 pm    Post subject: View/download C code for Random Sudoku Generator Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Wed Dec 10, 2008 7:39 am    Post subject: Reply with quote

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
View user's profile Send private message
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Wed Dec 10, 2008 11:28 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Wed Dec 10, 2008 8:48 pm    Post subject: Reply with quote

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
View user's profile Send private message
tarek

Joined: 31 Dec 2005
Posts: 153
:
Location: London, UK

Items
PostPosted: Wed Dec 10, 2008 9:00 pm    Post subject: Reply with quote

cardinal wrote:
try this animal :

.........
.4.......
...6..8..
...9.....
.....85..
...2.....
.......34
.69....2.
2.......6
That animal has no 1s & no 7s Embarassed Idea

tarek
Back to top
View user's profile Send private message
Lunatic

Joined: 11 Mar 2007
Posts: 166
:
Location: Ghent - Belgium

Items
PostPosted: Wed Dec 10, 2008 10:10 pm    Post subject: Reply with quote

cardinal wrote:
yes you are right. the speed is important Smile

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
View user's profile Send private message Send e-mail Visit poster's website
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Thu Dec 11, 2008 12:20 am    Post subject: Reply with quote

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
View user's profile Send private message
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Thu Dec 11, 2008 1:37 am    Post subject: Reply with quote

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
View user's profile Send private message
m_b_metcalf

Joined: 13 Mar 2006
Posts: 210
:
Location: Berlin

Items
PostPosted: Thu Dec 11, 2008 6:19 am    Post subject: Reply with quote

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
View user's profile Send private message
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Thu Dec 11, 2008 7:24 am    Post subject: Reply with quote

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
View user's profile Send private message
m_b_metcalf

Joined: 13 Mar 2006
Posts: 210
:
Location: Berlin

Items
PostPosted: Thu Dec 11, 2008 8:20 am    Post subject: Reply with quote

cardinal wrote:
thank you, but also it can have no solution Smile

so, i have to backtrack it anyway Sad 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
View user's profile Send private message
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Thu Dec 11, 2008 1:53 pm    Post subject: Reply with quote

......3..
....3.4.6
......2..
...5..6..
.4.......
.7...9...
...19....
126.83...
.........
Back to top
View user's profile Send private message
m_b_metcalf

Joined: 13 Mar 2006
Posts: 210
:
Location: Berlin

Items
PostPosted: Thu Dec 11, 2008 2:59 pm    Post subject: Reply with quote

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
View user's profile Send private message
cardinal

Joined: 08 Apr 2006
Posts: 40
:

Items
PostPosted: Thu Dec 11, 2008 3:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
hobiwan

Joined: 11 Feb 2008
Posts: 83
:

Items
PostPosted: Fri Dec 12, 2008 6:26 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Sudoku Programmers Forum Index -> Programming sudoku All times are GMT
Page 1 of 1

 
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
Sudoku Programmers topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group

Igloo Theme Version 1.0 :: Created By: Andrew Charron