array in sudoku?

im doing a program for sudoku solver.. below is the code i found from a website..
I dont understand y mark[10] and not mark[9]?
and the mark[matrix[x][i]] means?
thanks~

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int matrix[9][9];
int check(int x,int y,bool mark[10])
{
	int c=0;
	for(int i=1;i<=9;i++)
	{
		mark[i]=true;
		
	}
	for(int i=0;i<9;i++)
	{
		mark[matrix[x][i]]=false;
		mark[matrix[i][y]]=false;
	}

	x=x/3*3;
	y=y/3*3;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
	{
		mark[matrix[x+i][y+j]]=false;
		}
	}

your creating an array bool mark[10]

The value for that array starts with 0 and ends with 9

So mark[0] is the first value, not mark[1]
[ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ]
0 1 2 3 4 5 6 7 8 9 ==>> 10 element rite?
but.. in a sudoku is 9x9 box rite? sorry im kinda slow learner.. TT
thanks for reply ya~
The numbers stored in each box is from 1-9. They use these numbers as index to the mark array so instead of having to subtract one from the number each time, they made the array one bigger and never use mark[0] for anything.

EDIT:
Maybe they use the number 0 to represent that no number has been placed at that position. If that is the case this approach also avoids the need to check if the number is 0 because it will just set mark[0], which doesn't matter because the value of mark[0] will be ignored anyway.

Just to demonstrate, if mark was made size 9, instead of doing mark[matrix[x][y]] = false; you would have to do
1
2
3
4
if (matrix[x][y] != 0)
{
	mark[matrix[x][y] - 1] = false;
}
Last edited on
The way your doing it is [1][1] is column 0, row 1

Another way is
[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]
[10] [11] [12] [13] [14] [15] [16] [17] [18] [19]
[20] [21] [22] [23] [24] [25] [26] [28] [29] [30]

This will explain it better
http://www.cplusplus.com/doc/tutorial/arrays/
Go down to Multidimensional arrays
thanks peter and samuel~~ thank you very much~ ^^
Topic archived. No new replies allowed.