View previous topic :: View next topic |
Author |
Message |
| knehren
| Joined: 21 Jul 2009 | Posts: 2 | : | | Items |
|
Posted: Tue Jul 21, 2009 9:38 am Post subject: New here |
|
|
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 |
|
|
| lkSudoku
| Joined: 16 May 2009 | Posts: 60 | : | | Items |
|
Posted: Tue Jul 21, 2009 1:40 pm Post subject: |
|
|
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 |
|
|
| knehren
| Joined: 21 Jul 2009 | Posts: 2 | : | | Items |
|
Posted: Tue Jul 21, 2009 2:18 pm Post subject: |
|
|
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 |
|
|
| strmckr
| Joined: 24 Apr 2009 | Posts: 52 | : | | Items |
|
Posted: Tue Jul 21, 2009 2:51 pm Post subject: |
|
|
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 |
|
|
| energztm
| Joined: 21 Jul 2009 | Posts: 6 | : | | Items |
|
Posted: Tue Jul 21, 2009 3:00 pm Post subject: |
|
|
I'm not really sure how you guys got into programming,
Is there an easy to use website to learn? |
|
Back to top |
|
|
| strmckr
| Joined: 24 Apr 2009 | Posts: 52 | : | | Items |
|
Posted: Tue Jul 21, 2009 7:55 pm Post subject: |
|
|
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 |
|
|
| Lunatic
| Joined: 11 Mar 2007 | Posts: 166 | : | Location: Ghent - Belgium | Items |
|
|
Back to top |
|
|
|