The issue occurs in the following procedure. I have included the entire procedure, as the contained for loop calls the procedure.
The first part of the procedure generates all sets of size 'size', of ints 1 to 9 (inclusive), but in ascending order (not necessarily 1, 2, 3..., could be 1, 7, 9). If you've played sudoku before, you might recognise this as part of a 'locked set' algorithm that.
Once a set of size n is generated, the locked set algorithm uses it.
The issue in more detail: the for loop has two test conditions, one for ensuring 'value' does not exceed 9, the second test condition harder to explain, not essential, but prevent unnecessary computation (same set being generated many times). For some reason, the for loop ends when value reaches 10 (shown when I print out contents of array).
If I run procedure with size = 9, a set of 1 to 10 inc. is generated, so for loop is looping one too many times.
Code:
void setScan(int size, int value, int *arrayPtr, int count) // Size is size of wanted number set.
{
int remainSize = size; // Stops loop 1 generating same set as other recursions.
int x, y;
if(size > 0)
{
while((value <= 9) && (value <= (10 - size))) // This loop generates all sets of size 'size', and for each set, looks for a locked set.
{
if(value == 10);
printf("Hmm\n");
arrayPtr[count] = value;
remainSize--; // Size signifies how much of set left to create.
value++;
count++;
setScan(remainSize, value, arrayPtr, count);
}
}
else // size == 0, count == size of set
{
printf("Current set is: ");
for(y = 0; y <= count; y++)
printf("%i, ", arrayPtr[y]);
printf("\n");
/*for(y = 0; y <= 8; y++)
{
for(x = 0; x <= 8; x++)
{
//rowSetScan(x, y, arrayPtr, count);
//colSetScan(x, y, arrayPtr, count);
//boxSetScan(x, y, arrayPtr, count);
}
}*/
}
}