I can lead it also if you want, I don't really want to create one.
- Glenn
- Expert (Posts: 559)
- 27 May 2006 10:07:26 am
- Last edited by Glenn on 27 May 2006 10:17:26 am; edited 1 time in total
neither do i, i would do it brute force method (that would take hours, therefor automatic disqualification)
I would participate, but I already have too long a list of projects, some started, others not... Besides, I am still setting up my contest at my site...
gscm wrote:
brute force overnight, make 2 sudokus at a time, though I admit it is unefficiant, I might make it work better later
I have already tried this, i even transfered a good algorithm to c++, that failed miserable (oh and also i fixed the overwrite bug), it still didn't work!
KermMartian wrote:
Rivereye: that would be awesome. Want to discuss it on Skype later?
Whenever it is good for you we can do this.
KermMartian wrote:
Was it that it didn't work, or it was just too slow?
Too slow... I think i need to rethink my algorithm though...
I actually think that not only was it too slow, but the algorithm was worthless... I finished transfering it to c++ (speaking of which i need to go update the code i posted), and it still does not work, but there is one more thing i am going to change on it before i give up on that algorithm
-
Harq
- Calculator Deity (Posts: 1857)
- 27 May 2006 04:54:12 pm
- Last edited by Harq on 27 May 2006 05:06:41 pm; edited 1 time in total
I am working on the glitch now, i think it will generate a valid puzzle eventually, but i don't know... I am rereading all of the coding now to make sure i didn't accidentally make it subtract too many when it goes back or something stupid like that...
Edit: I did accidentally do something wrong, instead of just doing
column--; to have it try the same place again, I had column = column - 2;
so i am going to go over it a bit more, then recompile.
Edit: I did accidentally do something wrong, instead of just doing
column--; to have it try the same place again, I had column = column - 2;
so i am going to go over it a bit more, then recompile.
Look back at my previous post, i just posted that i did accidentally make a mistake.
P.S. It is pretty much a brute force algorithm, if it tries more than 25 times to place something (it was 15 or so on the calc), it will rewrite the previous row, and the current row.
In the process of fixing the algorithm, i screwed up the coding...
P.S. It is pretty much a brute force algorithm, if it tries more than 25 times to place something (it was 15 or so on the calc), it will rewrite the previous row, and the current row.
In the process of fixing the algorithm, i screwed up the coding...
Harq wrote:
Look back at my previous post, I just posted that I did accidentally make a mistake.
P.S. It is pretty much a brute force algorithm, if it tries more than 25 times to place something (it was 15 or so on the calc), it will rewrite the previous row, and the current row.
In the process of fixing the algorithm, I screwed up the coding...
Heh, that's essentially the way mine worked too. P.S. It is pretty much a brute force algorithm, if it tries more than 25 times to place something (it was 15 or so on the calc), it will rewrite the previous row, and the current row.
In the process of fixing the algorithm, I screwed up the coding...
HALLELUEA (how do you spell that?) IT (almost) WORKED! In about 2 or 3 seconds it made a sudoku puzzle, the only problem is that there are 9 0's... Hye, atleast i worked! Now i am going to check to make sure there are no illegal moves... Oh... there are...
wow... either my check function is worthless, or something very strange happened...
wow... either my check function is worthless, or something very strange happened...
OK here is a resulting puzzle, I also decided to add a quick function call at the end that checks to see if all the moves are legal, so far everytime it has said not legal
Here is a pic:
I am wondering why it is doing this, escpecially the empty spaces!
And here is the code (i know i need to optomize, but ignore that for now) :
Code:
I am an idiot... I just realized that there are no 9's generated by the random number feature, it was 0 - 8, not 1 - 9, i fixed that in the code now, now its just the generating issue... So ignore the 0 problem and just look at the totally illegal moves that are generated, lol
Here is a pic:
I am wondering why it is doing this, escpecially the empty spaces!
And here is the code (i know i need to optomize, but ignore that for now) :
Code:
/* OK, this is my rewrite of my earlier Sudoku program.
I am not sure the technique works, but we shall see...
#################################################################
If you do not know C++ and you are reading this code, just know that arrays start with 0
(measures distant from start really), not 1.
*/
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
int row,column,num,counter,repeat;
int grid[9][9];
void disp(void);
void overwrite(void);
int sudrand(void);
int check(int n);
int totalcheck(void);
int main() {
srand(time(NULL)); //Sets rand seed
cout << "\n Generating puzzle...";
for(row = 0; row <= 8; row++) { // Y loop
disp();
repeat = 0;
for (column = 0; column <= 8; column++) { // X llop
num = sudrand(); //Calls sudrand and gets a random number
counter = check(num); //counter = the return value of check(num)
//0 if move is legal, 1 if illegal
if (counter == 1) {
repeat++;
counter = 0;
column--;
}
if (counter == 0)
grid[row][column] = num;
if (repeat >= 25 and row > 1) { //if illegal move was made 25 or more times, restart last row
repeat = 0;
row = row - 2;
column = 8;
overwrite();
}
}
}
counter = totalcheck();
disp(); //displays the resulting puzzle
cout << "\n\n";
if (counter == 0)
cout << "All numbers are legal";
if (counter == 1)
cout << "Not all numbers are legal";
cout << endl;
cin >> counter;
}
void disp() { //displays puzzle
int t;
cout << endl;
for (int r = 0; r <= 8 ; r++) {
cout << endl;
for (int c = 0; c <= 8; c++) {
cout << grid[r][c] << " ";
}
}
return;
}
int sudrand() { //generates a random number, 1 - 9
return (rand() % 9) + 1;
}
int check(int n) {
int r,c,max;
//Horizontal check
r = row;
for (c = 0; c <= 8; c++) {
if (grid[r][c] == n)
return 1;
}
//Vertical check
c = column;
for (r = 0; r <= 8; r++) {
if (grid[r][c] == n)
return 1;
}
//square check
if (row <= 3)
r = 1;
if (row >= 4 and row <= 6)
r = 4;
if (row >= 7)
r = 7;
if (column <= 3)
c = 1;
if (column >= 4 and column <= 6)
c = 4;
if (column >= 7)
c = 7;
max = c+3;
for (int d = 0;d <= 8; d++) {
if (c == max) {
c = c-3;
r++;
}
if (grid[r][c] == n)
return 1;
c++;
}
return 0;
}
void overwrite() {
for (int r = row+1; r <= row+2; r++) {
for (int c = 0; c <=8; c++) {
grid[r][c] = 0;
}
}
return;
}
int totalcheck() {
int checkc;
for (int r = 0; r <= 8; r++) {
for (int c = 0; c <= 8; c++) {
checkc = check(grid[r][c]);
if (checkc == 1)
return 1;
}
}
return 0;
}
I am an idiot... I just realized that there are no 9's generated by the random number feature, it was 0 - 8, not 1 - 9, i fixed that in the code now, now its just the generating issue... So ignore the 0 problem and just look at the totally illegal moves that are generated, lol
» Goto page Previous 1, 2, 3, 4, 5, 6 Next
» View previous topic :: View next topic
» View previous topic :: View next topic
Page 5 of 6
» All times are UTC - 5 Hours
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
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
Advertisement