3 Replies Latest reply on Apr 19, 2007 11:07 PM by 807606

Sudoku algorithm

Hi. I have a small problem. I attend to a java-programming class in a university in Norway, and we've got this assignment that we have to do in order to be able to take the final exam. I'm not nearly finished, and in I have to deliver it in like 5 hours. So we're supposed to make a java-program that solves a sudoku, and we're supposed to use this algorithm:
http://www.menneske.no/sudoku/eng/reducingmethodsdc.html
My problem is that i don't see how I can code this into java. I dunno where to start. I have a method for finding the number of allowed numbers in the different cells in a row, colum or box, and also a method for finding the allowed numbers in the cells. What I need is some kind of outline on how to write this algorithm in java. Like what control flow statements do I use, and how do i nest and use them etc. (I'm not very experienced in java.)
Can anyone help me out?
• 1. Re: Sudoku algorithm
Looks like you are stuffed unless you can take a reasonable excuse to your examiner. Nobody here is going to write the program for you - that would be helping you cheat.
• 2. Re: Sudoku algorithm
Create a two dimensional array
``int[ ][ ] array = new int[10][10];``
add whatever the numbers in the board are supposed to be.

then something sort of like this:
``````int number, number2, number3;

array[1][3] = number;
array[1][5] = number2;
array[3][5] = number3;

for(int i=0; i < 10; i++)
{
for(int j=0; j < 10; j++)
{
if(array[i][j] == number || array[i][j] == number2 || array[i][j] == number3)
{
array[i][j] = 0;
}
}//for(columns)
}//for(rows)``````
something like that, you'll have to tinker with it and figure out other stuff
• 3. Re: Sudoku algorithm
Thx shlumph. I'll try that! :)

sabre150: I'm not asking you to write the program for me, I just need some help to get stardet.