Don't understand a function in this sudoku solver

Jan 17, 2009 at 9:45am
http://rapidshare.com/files/lain.cpp.html

I understand everything what the solver does but I do not understand what the guess_number() function is doing in the code.
Would someone please explain me how the guess_number() is working ?

Thanks for reading,
G'day

P.S. - I am giving the rapidshare link because I am getting the error : Field "Content" too long: max is 9000 characters
Last edited on Jan 26, 2009 at 4:45pm
Jan 17, 2009 at 1:15pm
Can you please post just that function?
Jan 17, 2009 at 2:17pm
I would post the function man, but trust me, it'd not make any point if you didn't know what arguments were passed from the main function to that function...
Jan 17, 2009 at 3:17pm
...
Last edited on Jan 26, 2009 at 4:47pm
Jan 17, 2009 at 3:18pm
.
Last edited on Jan 26, 2009 at 4:49pm
Jan 17, 2009 at 3:18pm
.
Last edited on Jan 26, 2009 at 4:48pm
Jan 17, 2009 at 3:19pm
Last edited on Jan 26, 2009 at 4:50pm
Jan 17, 2009 at 3:40pm
Is this what you're stumbling on?

1
2
3
4
5
6
7
8
9
if(num++==10)
	{
		num=1;
		if(col++==9)
		{
			col=0;
			row++;
		}
	}


++== is testing if the number is equal to something, and adding one to it after the conditional test... so if it is 10 it will be reset to 1, otherwise 1 is just added... same thing is happening on your column... its basically advancing the number and the column if such an action is applicable to the situation.
The rest of that function has pretty obvious comments...
BTW I didn't even read the rest of the program, I could have told you that much just seeing the function.

Another way of coding it would be:

1
2
3
num++;
if(num == 11)
   num = 1; //etc. 
Last edited on Jan 17, 2009 at 3:45pm
Jan 17, 2009 at 4:03pm
Thank you Malachi, but unfortunately that wasn't it.
The problem is with the logic, I do not get the logic of the work that the function performs...
Topic archived. No new replies allowed.