This is the code and there is something wrong with the check column function. I am unsure and need help.
#include <iostream>
using namespace std;
int sudoku_solution[9][9];
const int array_size = 9;
inline int random()
{
return rand() % array_size + 1;
}
bool check_column(int value, int row, int column)
{
if(row == 0)
{
return true;
}
for(int i = row; row > 0; row--)
{
/* if(column == 7)
{
cout << "ROW: " << row << "\n";
cout << "COLUMN: " << column << "\n";
cout << "value : " << value << "\n";
cout << "sudoku_solution: " << sudoku_solution[row - 1][column] << "\n";
system("PAUSE");
}
if(value == sudoku_solution[row - 1][column])
{
return false;
}*/
}
return true;
}
int approach_5(int array[], int size, int row)
{
int numbers[size];
int try_count = 0;
for(int i=0; i < size; i++)
{
numbers[i] = i + 1;
}
for(int i = 0; i < 9; i++)
{
array[i] = numbers[random() - 1];
try_count++;
while(array[i] == 0 || !check_column(array[i], row, i))
{
/*if (row ==7)
{
for ( int j = 0; j < 9; j++)
{
cout << " DEBUG" << j << array[j]<< "\n";
}
} */
array[i] = numbers[random() - 1];
try_count++;
}
numbers[array[i] - 1] = 0;
}
return try_count;
}
void fill_sudoku_row(int source_row[], int cells_to_fill, int dest_row_number)
{
for(int i=0;i<9;i++)
{
sudoku_solution[dest_row_number][i] = source_row[i];
}
}
int main()
{
int row[9];
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
sudoku_solution[i][j] = 0;
}
}
for(int d_row=0; d_row<8; d_row++)
{
approach_5(row, 9, d_row);
fill_sudoku_row(row, 9, d_row);
}
//fill row
for(int i=0;i<9;i++)
{
for(int j=0;j<9;j++)
{
cout << sudoku_solution[i][j] << " ";
}
cout << "\n";
}
system("PAUSE");
return 0;
}