Hi all, <br>
<br>
If you aren't aware of Sudoku, this is it - <a href="http://www.sudoku.com/">http://www.sudoku.com/</a><br>
<br>
Big craze at my office, and I've just been wracking my brains to try and think of how to model it in Python (in order to solve.)<br>
<br>
What I'm not sure of is how to implement it. <br>
<br>
Basic rundown of a Sudoku puzzle is - <br>
<br>
<br>
Generally composed of 9 x 9 squares, with the box divided further into
nine 3 x 3 mini-squares. Certain numbers are given at the start. <br>
<br>
Sudoku puzzles follow these rules - <br>
<br>
Each column, row and mini-square must contain the complete set of numbers 1 - 9.<br>
The numbers do not have to be sequential.<br>
Each column, row, and mini-square can only contain each number once<br>
<br>
So that's it. So, to implement...<br>
<br>
I was thinking, a list of lists of lists.... <br>
[grid[0], grid[1], grid[2], <br>
grid[3], grid[4], grid[5],<br>
grid[6], grid[7], grid[8] ]<br>
<br>
[ <br>
[<br>
[a,b,c],<br>
[d,e,f,],<br>
[g,h,i]<br>
],<br>
[<br>
[j,k,l],<br>
[m,n,o],<br>
[p,q,r]....<br>
<br>
So forth. This approach gets a little confusing in terms of array arithmetic but it's livable. <br>
<br>
Now each variable can be [1-9]....<br>
<br>
Variable a (grid[0][0][0]) can be 1 unless <br>
<br>
grid - any member of grid[0] is 1<br>
row - any member of grid[1][0] or grid[2][0] is 1<br>
column - grid[3][x][0] or grid[6][x][0] is 1 (where x is an index of 0 to 2)<br>
<br>
My current approach is to start with each variable as a list of numbers [1-9] and to pop numbers based on the above rules, <br>
but I got thinking about sets and what not, and wondered if they would work better, unions and intersections and whatnot. <br>
<br>
Problem is, I don't know the first thing about set mathematics. <br>
<br>
Any pointers in the right direction would be gratefully appreciated. <br>
<br>
Regards, <br>
<br>
<br>
Liam Clarke<br>-- <br>'There is only one basic human right, and that is to do as you damn well please.<br>And with it comes the only basic human duty, to take the consequences.'