Discussion:
Sudoku creator in Prolog
(too old to reply)
abhi
2010-01-21 08:49:25 UTC
Permalink
Hallo ,
can anyone help me out in creating a 9 * 9 Sudoku with prolog and
write in on file .
Would be great if anyone can post me the source code.
Thanks all
abhi
2010-01-21 08:56:44 UTC
Permalink
Post by abhi
Hallo ,
can anyone help me out in creating a 9 * 9 Sudoku with prolog  and
write in on file .
Would be great if anyone can post me the source code.
Thanks all
I can only find sudoku solver , but i need a simple creator !
Martin Riener
2010-01-21 09:50:31 UTC
Permalink
Post by abhi
Post by abhi
Hallo ,
can anyone help me out in creating a 9 * 9 Sudoku with prolog and
write in on file .
Would be great if anyone can post me the source code.
Thanks all
I can only find sudoku solver , but i need a simple creator !
What about a generate and test pattern? Just fill in an empty 9x9 field
randomly, at each step check if there is only one solution left.

hth Martin
Wit Jakuczun
2010-01-21 10:03:40 UTC
Permalink
Post by Martin Riener
Post by abhi
I can only find sudoku solver , but i need a simple creator !
What about a generate and test pattern? Just fill in an empty 9x9 field
randomly, at each step check if there is only one solution left.
findall with existing solver should work better.

Best regards,
Wit Jakuczun, http://wlogsolutions.com
abhi
2010-01-21 10:49:00 UTC
Permalink
Post by Martin Riener
Post by abhi
Post by abhi
Hallo ,
can anyone help me out in creating a 9 * 9 Sudoku with prolog  and
write in on file .
Would be great if anyone can post me the source code.
Thanks all
I can only find sudoku solver , but i need a simple creator !
What about a generate and test pattern? Just fill in an empty 9x9 field
randomly, at each step check if there is only one solution left.
hth Martin
I really have no idea how to write it in prolog , i did it like this
in java .. can you please give sample code for generate and test
pattern in prolog :)

int[][] best = new int[N][N];
int bestDifficulty = 0;
int bestGiven = N*N+1;
int bestTry = 0;

int tries = 0;
// Generate 100 puzzles and pick the most difficult one
while(tries < 100) {
countGiven = 0;
difficulty = 0;
// Clean the given numbers, but keep the grid intact
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
this.given[i][j] = 0;
}
}

// Select 17 random numbers to show
// 17 is an absolute minimum. Any less and the puzzle is
garanteed to be unsolvable.
this.randomGiven(17);
difficulty = this.solvable();

// Keep adding numbers until the puzzle is solvable
while(difficulty==0) {
this.addRandomGiven();
difficulty = this.solvable();
}
if(countGiven <= bestGiven) {
// If this puzzle is better then anything we've found so
far, store it
bestGiven = countGiven;
bestDifficulty = difficulty;
bestTry = tries;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
best[i][j] = this.given[i][j];
}
}
if(bestGiven < 35 && bestDifficulty > 960)
break; // Good enough. Stop searching.
}
tries++;
}

// Restore the best grid:
countGiven = bestGiven;
difficulty = bestDifficulty;
if(this.output)
System.out.println("Puzzle "+bestTry+" is best");

String s = "" ;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
this.given[i][j] = best[i][j];
}
}
for(int x = 0 ;x <= 8 ; x++) {
s+="\n";
for(int i = 0 ; i <= 8 ; i++)
s += best[i][x];

}
Chip Eastham
2010-01-21 14:21:26 UTC
Permalink
Post by abhi
I really have no idea how to write it in prolog , i did it like this
in java .. can you please give sample code for  generate and test
pattern in prolog :)
                int[][] best = new int[N][N];
                int bestDifficulty = 0;
                int bestGiven = N*N+1;
                int bestTry = 0;
        int tries = 0;
        // Generate 100 puzzles and pick the most difficult one
                while(tries < 100) {
                        countGiven = 0;
                        difficulty = 0;
                        // Clean the given numbers, but keep the grid intact
                for(int i=0; i<N; i++) {
                    for(int j=0; j<N; j++) {
                        this.given[i][j] = 0;
                    }
                }
          // Select 17 random numbers to show
          // 17 is an absolute minimum. Any less and the puzzle is
garanteed to be unsolvable.
[snip]

Hi, abhi:

Since you say you wrote this Java program, let me
ask about the comment that 17 is "an absolute
minimum." Do you have a reference for this?
I'm aware that 17-cell Sudoku exist in some
profusion, and that catalogs of the known
examples have been systematically tested to
see if any of them could be reduced to 16
cells having yet a unique solution, without
success. But I'm not aware of any proof
(by exhaustive search or otherwise) that no
16-cell Sudoku exists.

Also, it might be helpful if you explained
in more detail what the Prolog Sudoko solver
available to you does. I'd be a bit leary
of wrapping a "Sudoku generator" around such
a solver if possibly the solver code does
not terminate when presented with a puzzle
for which no solution or multiple solutions
exist. It would be interesting as well to
know what representation is used for the
solver, so that suggestions about generating
inputs could be more relevant.

regards, chip
Ulrich Neumerkel
2010-01-21 13:36:22 UTC
Permalink
Post by abhi
Hallo ,
can anyone help me out in creating a 9 * 9 Sudoku with prolog and write in on file .
Would be great if anyone can post me the source code.
Take an existing Sudoku solver.

Find somehow (e.g. labeling "randomly") a valid solution.

While there is a unique solution: generalize the Sudoku
(replacing an entry by a free new variable).

That is: after each step of generalization you have to
solve again the Sudoku to ensure that there is still
a unique solution.
A.L.
2010-01-21 15:05:30 UTC
Permalink
On Thu, 21 Jan 2010 00:49:25 -0800 (PST), abhi
Post by abhi
Hallo ,
can anyone help me out in creating a 9 * 9 Sudoku with prolog and
write in on file .
Would be great if anyone can post me the source code.
Thanks all
What university?

A.L.
a***@hotmail.com
2017-04-27 04:18:40 UTC
Permalink
Hi..

Excuse me..
I want the code for sudoku game in Amzi prolog..

please help me..

Loading...