示例#1
0
static int* Twos(int* puzzle) {
	int a, b, i, n;
	int* rowList = (int*) (malloc)(sizeof(int) * 9);
	int* colList = (int*) (malloc)(sizeof(int) * 9);
	for (a = 0; a < 9; a++) {
		for (b = 0; b < 9; b++) {
			rowList[b] = puzzle[SUDOKU_INDEX(a,b)];
			colList[b] = puzzle[SUDOKU_INDEX(b,a)];
		}
		for (i = 0; i < 9; i++)
			for (n = i + 1; n < 9; n++) {
				if (rowList[i] == rowList[n] && rowList[i] < 100) {
					RemoveRow(puzzle, a, rowList[i] / 10);
					RemoveRow(puzzle, a, rowList[i] % 10);
					puzzle[SUDOKU_INDEX(a,i)] = rowList[i];
					puzzle[SUDOKU_INDEX(a,n)] = rowList[i];
				}
				if (colList[i] == colList[n] && colList[i] < 100) {
					RemoveCol(puzzle, a, colList[i] / 10);
					RemoveCol(puzzle, a, colList[i] % 10);
					puzzle[SUDOKU_INDEX(i,a)] = colList[i];
					puzzle[SUDOKU_INDEX(n,a)] = colList[i];
				}
			}
	}
	int r, c;
	int* boxList = (int*) (malloc)(sizeof(int) * 9);
	for (a = 0; a < 9; a += 3)
		for (b = 0; b < 9; b += 3) {
			for (r = a; r < a + 3; r++)
				for (c = b; c < b + 3; c++)
					boxList[(r - a) * 3 + (c - b)] = puzzle[SUDOKU_INDEX(r,c)];
			for (i = 0; i < 9; i++)
				for (n = i + 1; n < 9; n++)
					if (boxList[i] == boxList[n] && boxList[i] < 100) {
						RemoveBox(puzzle, a, b, boxList[i] / 10);
						RemoveBox(puzzle, a, b, boxList[i] % 10);
						puzzle[SUDOKU_INDEX((i/3)+a,(i%3)+b)] = boxList[i];
						puzzle[SUDOKU_INDEX((n/3)+a,(n%3)+b)] = boxList[i];
					}
		}
	free(rowList);
	free(colList);
	free(boxList);
	return puzzle;
}
示例#2
0
//Removes a number from a row/col/box once it is found
static void Remove(int* puzzle, int r, int c) {
	int value = puzzle[SUDOKU_INDEX(r,c)];
	RemoveRow(puzzle, r, value);
	RemoveCol(puzzle, c, value);
	int rowbox = (r / 3) * 3;
	int colbox = (c / 3) * 3;
	RemoveBox(puzzle, rowbox, colbox, value);
	return;
}
void
GLFitParameterTable::SetFitDescription
	(
	const GLFitDescription& fit
	)
{
	RemoveAllRows();
	itsNameList->DeleteAll();
	itsStartValues->RemoveAll();
	itsFitValues->RemoveAll();
	itsErrorValues->RemoveAll();

	GLFitDescription::FitType type = fit.GetType();
	if (fit.RequiresStartValues())
		{
		if (!itsHasStartValues)
			{
			InsertCols(kStartColIndex, 1, kDefColWidth);
			itsColHeaderWidget->SetColTitle(2, kParmStartTitle);
			itsHasStartValues	= kJTrue;
			AdjustColWidth();
			}
		}
	else
		{
		if (itsHasStartValues)
			{
			RemoveCol(kStartColIndex);
			itsHasStartValues	= kJFalse;
			AdjustColWidth();
			}
		}

	const JSize count	= fit.GetParameterCount();
	AppendRows(count);
	for (JIndex i = 1; i <= count; i++)
		{
		JString* str = new JString("");
		fit.GetParameterName(i, str);
		itsNameList->Append(str);
		itsStartValues->AppendElement(0);
		itsFitValues->AppendElement(0);
		itsErrorValues->AppendElement(0);
		}			
}
void
GLFitParameterTable::ShowStartCol
	(
	const JBoolean show
	)
{
	if (itsHasStartValues == show)
		{
		return;
		}
	if (itsHasStartValues)
		{
		RemoveCol(kStartColIndex);
		itsHasStartValues	= kJFalse;
		AdjustColWidth();
		}
	else
		{
		InsertCols(kStartColIndex, 1, kDefColWidth);
		itsColHeaderWidget->SetColTitle(2, kParmStartTitle);
		itsHasStartValues	= kJTrue;
		AdjustColWidth();
		}
}