What I am trying to do is create a random 9x9 matrix. Ultimately working towards randomly generating a Sudoku puzzle. I am very new to array usage/manipulation so this problem is baffling me.
If you know of Sudoku basically you can't have duplicate numbers in any rows/columns.
My problem is figuring out how to remove duplication of the randomly generated numbers in the rows.
Thus far, I have been able to create a randomly generated 9x9 matrix. That is about as far as I have made it though.
I was wondering, at the very least if someone had an idea on how to remove duplication within each of the rows.
Here is what I have so far.
Code:
#include <iostream>
#include <ctime>
using namespace std;
void matrixOne(int & x, int & y, int matrix[][9]);
int main(void)
{
int matrix[9][9];
int x;
int y;
matrixOne(x,y,matrix);
return 0;
}
void matrixOne(int & x, int & y, int matrix[][9])
{
for(x = 0; x < 9; x++)
{
cout << endl;
for(y=0; y < 9; y++)
{
matrix[x][y] = rand()%9+1;
cout << " " << matrix[x][y];
}
}
cout << endl;
return;
}
My output looks like this :
Code:
6 9 8 5 9 2 4 1 8
3 9 3 8 7 8 6 8 9
4 1 1 7 6 1 5 8 7
6 9 6 3 1 3 1 7 5
9 2 8 4 3 7 3 4 7
3 4 8 3 2 6 6 2 7
4 8 3 4 8 5 5 3 6
7 1 2 5 6 5 5 6 1
6 7 8 6 4 7 4 3 1
Press any key to continue
Any help or suggestions would be greatly appreciated.