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   

New here

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

Joined: 21 Jul 2009
Posts: 2
:

Items
PostPosted: Tue Jul 21, 2009 9:38 am    Post subject: New here Reply with quote

Hi, I'm sorry if I'm bothersome, but I'm new to programming (just installed Visual Basic last saturday)!

I am trying to create a generator of nbyn grids of random numbers with the guarantees of no duplicate numbers in row/coloumn.

I have gotten to the part of having a 4x4 grid with all random numbers between 1 and 4. What I can't figure out is what to do to ensure uniqueness of the numbers.

I believe this is the most trivial problem possible, but being new I really can't fathom it.

Any help please?
Back to top
View user's profile Send private message
lkSudoku

Joined: 16 May 2009
Posts: 60
:

Items
PostPosted: Tue Jul 21, 2009 1:40 pm    Post subject: Reply with quote

In general, you can setup a board, and if it is not valid, you can backtrack and change the numbers, you can continue to backtrack and try different numbers until a valid board is created

In the 4x4 case (or 2x2 if you consider one block), the total number of possible different boards which may be valid is less than a hundred (each of the 4 blocks has 4!=24 options), so for that case, you can simply generate all possible boards, and check each one for validity

A more advanced method would be to decide on some solution strategy, and for a given partial board try to solve it with the solution algorithm and add as much numbers as the solution finds, when the solution algorithm gets stuck, you need to add another random number; In this method too, when you encounter a board that cannot be solved by the solution strategy, you should backtrack from the last random choice and make sure you do not repeat the same random choices that caused an invalid board
Back to top
View user's profile Send private message Send e-mail
knehren

Joined: 21 Jul 2009
Posts: 2
:

Items
PostPosted: Tue Jul 21, 2009 2:18 pm    Post subject: Reply with quote

Thing is, I'm not really trying to create a Sudoku, but a base to work on to to make a number of different logic games. Moreover, the 4x4 size is not final, and I will need to work on 5x5, 6x6, even 7x7 grids.

I speak of games such as Skyscrapers, Futoshiki, Easy as ABC and so forth. All have the same basic rules (a nxn latin square). Never seem to be able to create the actual grid.
Back to top
View user's profile Send private message
strmckr

Joined: 24 Apr 2009
Posts: 52
:

Items
PostPosted: Tue Jul 21, 2009 2:51 pm    Post subject: Reply with quote

to check the puzzle gerneated is actually valid "unique"

a program needs to be written that can test each cell 1 at a time and "count" the number of options per cell that are valid given the restraints of the board.

via a back tracking method of some sort that can test all cells in conjuction with all others.

usually most people utilize:

Dancing links
ie DLX, algrothium X

to back track a matrix and calculate the total number of solutions.
Back to top
View user's profile Send private message
energztm

Joined: 21 Jul 2009
Posts: 6
:

Items
PostPosted: Tue Jul 21, 2009 3:00 pm    Post subject: Reply with quote

I'm not really sure how you guys got into programming,
Is there an easy to use website to learn?
Back to top
View user's profile Send private message
strmckr

Joined: 24 Apr 2009
Posts: 52
:

Items
PostPosted: Tue Jul 21, 2009 7:55 pm    Post subject: Reply with quote

some users are programers as carrers others

are hobbiest that enjyed it from school. (like me)

depends on what you already know or are intrested in learning

i how ever recomend starting with some basic lagnauge that is fairly easy to learn.

like:
turbo Pascal: {free pascal 2.24 is free ware and pretty good}

if your intrested in the program feel free to pm me and i'll provide all the links i can find and the complier softare to go with it

so you can first learn the basics befor trying to accomplish more difficult tasks.
Back to top
View user's profile Send private message
Lunatic

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

Items
PostPosted: Thu Jul 23, 2009 9:48 am    Post subject: Re: New here Reply with quote

knehren wrote:
Any help please?


For any NxN grid...

Map all cells from the grid in an array in a random order, and then fill the grid (using that array as a pointer to your random ordered cells) with the technique based upon the 4 line brute solver, but skip the box-check.

Some links:
http://www.setbb.com/sudoku/viewtopic.php?t=774&mforum=sudoku
http://www.setbb.com/sudoku/viewtopic.php?t=1389&start=0&postdays=0&postorder=asc&highlight=&mforum=sudoku
http://www.setbb.com/sudoku/viewtopic.php?p=10207&mforum=sudoku#10207
_________________
Marc
~~~<><~~~<><~~~<><~~~<><~~~
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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