All pastes #2092423 Raw Edit

Untitled

public text v1 · immutable
#2092423 ·published 2011-10-22 05:16 UTC
rendered paste body
void MultipleSolution()
{
	cout << "No Unique Solution";
	exit(0);
}

bool solutionFound = false;
void CheckSolutions(vector<NumberCell*>& cells, int index)
{
	if (index == cells.size())
	{
		if (solutionFound == true)
		{
			MultipleSolution();
		}
		else
		{			
			solutionFound = true;
		}
		return;
	}

	for (int i = 1; i <= 9; i++)
	{
		if(cells[i]->canPutNumber(i))
		{
			cells[i]->setNumber(i);
			CheckSolutions(cells, index + 1);
		}
	}

	// Before backtracking, better set the number back to 0
	cells[index]->setNumber(0);

	return;
}

void CheckForSolutions(vector<NumberCell*>& cells)
{
	CheckSolutions(cells, 0);
	if (solutionFound == false)
	{
		cout << "No Solution";
	}
	else
	{
		cout << "Valid Puzzle";
	}
	exit(0);
}