I have always been a fan of sudoku.
The first program I wrote for sudoku used visual basic.
I then rewrote it in C to run on linux.
I expanded it to C++ and incorporated all the functions in a .dll
I used this .dll in a VB program to run on windows.
http://sourceforge.net/projects/mysudoku/files/
I wanted a break from my weather station project.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1283073954
It is not possible to have the whole sudoku solution in memory.
This would take 81 * what I have used.
My sudokuarray uses 33333*3 = 729 bytes.
It could be done with external memory.
The program prints out a random completed sudoku each time its run.
A LCD display and a joystick would be able to display the full sudoku as I have done in the linux/windows program.
The program uses brute force. Random numbers are selected until we have a complete solution. No attempt has been made to use the finer rules of sudoku construction.
It’s runs in fractions of a second on a PC.
It takes 1 to 20 seconds on the arduino.
The code is in three parts the first part is:
//sketch for Arduino 2009 (with 328)
//each time the sketch runs it prints out a random completed sudokuchar sudokuarray[3][3][3][3][3][3];
char arraynumber = 0;void setup()
{
Serial.begin(9600); // initialize serial communications at 9600
randomSeed(analogRead(0));
}//end of setupvoid loop()
{
generatesudoku();
if(arraynumber > 80)
{
printout(); //solved sodoku
while ( 0 == 0)
asm volatile(“nop”); //sit here after printed one sudoku
}//end of print out}//end of loop
void generatesudoku(void) //generate a sudoku
{
construct(); //start with new array
arraynumber = 0;
boolean noblanks = true;while((arraynumber < 80) && noblanks)
{
char x = random(9);
char y = random(9);
char number = random(9);
setnumber(x,y,number);
checkselection();for(char xl = 0; xl <3; xl++)
{
for(char yl = 0; yl <3; yl++)
{
for(char xs = 0; xs <3; xs++)
{
for(char ys = 0; ys <3; ys++)
{char numberselected = 0; //find how many zero’s in this box
for(char yn = 0; yn <3; yn++)
{
for(char xn = 0; xn <3; xn++)
{
if( sudokuarray[xl][yl][xs][ys][xn][yn] == 0)
numberselected += 1; //count number in this box
}//next xn
}//next yn
if(numberselected == 9)
noblanks = false;
}//next ys
}//next xs
}//next yl
}//next xl…checked all for any blanks}//end of get random sudoku
}//end of generate sudoku