private void SolveForQuadrants() { for (int i = 0; i < QUADS; i++) { int[] PossibleAnswerArray = new int[NUM_VALS]; int[] PossibleCellArray = new int[NUM_VALS]; int StartOfQuadrantIndex = (i % QUAD_ROWS) * QUAD_ROWS + (i / QUAD_ROWS) * CELLS_PER_THREE_QUADS; for (int j = 0; j < QUAD_CELLS; j++) { int idx = StartOfQuadrantIndex + j % QUAD_COLS + (int)Math.Floor((double)(j / QUAD_COLS)) * COLS; if (_Cells.TryGetValue(idx, out CellHashset Cell)) { if (!Cell.IsAnswered()) { foreach (int answer in Cell.PossibleAnswers) { PossibleAnswerArray[answer - 1]++; PossibleCellArray[answer - 1] = idx; } } else { PossibleAnswerArray[Cell.Answer - 1] = 2; } } } // value is -1 from the actual value for (int value = 0; value < NUM_VALS; value++) { // if the PossibleAnswerArray holds a 1, only 1 cell can have that value so it's the answer if (PossibleAnswerArray[value] == 1) { SetCellAnswer(PossibleCellArray[value], value + 1); } } } }
private void SolveForRows() { for (int i = 0; i < ROWS; i++) { int[] PossibleAnswerArray = new int[NUM_VALS]; int[] PossibleCellArray = new int[NUM_VALS]; for (int j = i * COLS; j < (i + 1) * COLS; j++) { if (_Cells.TryGetValue(j, out CellHashset Cell)) { if (!Cell.IsAnswered()) { foreach (int answer in Cell.PossibleAnswers) { PossibleAnswerArray[answer - 1]++; PossibleCellArray[answer - 1] = j; } } else { PossibleAnswerArray[Cell.Answer - 1] = 2; } } } // value is -1 from the actual value for (int value = 0; value < NUM_VALS; value++) { // if the PossibleAnswerArray holds a 1, only 1 cell can have that value so it's the answer if (PossibleAnswerArray[value] == 1) { SetCellAnswer(PossibleCellArray[value], value + 1); } } } }