1.

Solve : c++ Sudoku?

Answer»

There is almost always 1 NUMBER that has multiples? i am just checking rows, and then later check the columns, and then 3x3. Step by Step.

Code: [SELECT]int board[9][9] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0}
};

srand((unsigned)time(0));

for(int p = 0; p < 9; ++p) //Rows
{
for(int x = 0; x < 9; ++x) //Columns
{
board[p][x] = (RAND()%9)+1; //Random Number

for(int z = 0; z < x; ++z) //Check
{
if((board[p][x] == board[p][z])) //|| board[p][x] == board[z][x]
{
board[p][x] = (rand()%9)+1;
--z;
}
}

printf(ToCharArray(board[p][x]));
}
printf("\N");
}

output:

[6]7248391[6]
[4]16587[4]96
6[7]9[7]15285
367142589
[8]19[8]24576
1[8]7352[8]96
[1]596483[1]2
19[2]64[2]873
943726158
Code: [Select]
srand((unsigned)time(0));

for(int p = 0; p < 9; ++p) //Rows
{
for(int x = 0; x < 9; ++x) //Columns
{
board[p][x] = (rand()%9)+1; //Random Number

for(int z = 0; z < x; ++z) //Check
{
if((board[p][x] == board[p][z])) //|| board[p][x] == board[z][x]
{
--x;
break;
}
}
}
}

output:
413968725
718936452
395417286
568493127
349568271
196583724
649527381
612958374
298157436



Discussion

No Comment Found