static void Main(string[] args) { SudokuValidator sudokuValidator = new SudokuValidator(); //int[,] arraySudoku = sudokuValidator.generateDefaultSudoku(SUDOKU_SIZE); //int[,] arraySudoku = sudokuValidator.generateSudoku(SUDOKU_SIZE); // int[,] arraySudoku = sudokuValidator.generateBigSudoku(); int[,] arraySudoku = sudokuValidator.generateSudoku16(); // Thread.Sleep(1000); DateTime firstDt2 = DateTime.Now; resolveMonoThread(arraySudoku); DateTime endDt2 = DateTime.Now; Console.WriteLine(endDt2 - firstDt2); DateTime firstDt = DateTime.Now; resolveMultiThread(arraySudoku); DateTime endDt = DateTime.Now; Console.WriteLine(endDt - firstDt); Console.ReadLine(); }
static void Main(string[] args) { int[,] arr = new int[, ] { { 1, 2, 3, 4, 5, 6, 7, 8, 9 }, { 2, 3, 4, 5, 7, 7, 8, 9, 1 }, { 3, 4, 5, 6, 7, 8, 9, 1, 2 }, { 4, 5, 6, 7, 8, 9, 1, 2, 3 }, { 5, 6, 7, 8, 9, 1, 2, 3, 4 }, { 6, 7, 8, 9, 1, 2, 3, 4, 5 }, { 7, 8, 9, 1, 2, 3, 4, 5, 6 }, { 8, 9, 1, 2, 3, 4, 5, 6, 7 }, { 9, 1, 2, 3, 4, 5, 6, 7, 8 } }; var result = SudokuValidator.Validate(arr); if (result.isValid) { Console.WriteLine("Sudoku is valid"); } else { Console.WriteLine(result.message); } }
private void btnLoad_Click(object sender, EventArgs e) { var arryEnum = Enum.GetValues(typeof(AlphabeticalEnum)); var valueStrings = new string[arryEnum.Length][]; foreach (var line in arryEnum) { valueStrings[line.GetHashCode()] = new string[arryEnum.Length]; for (int col = 0; col < arryEnum.Length; col++) { var coord = $"{line}{col + 1}"; var txt = this.Controls[coord]; var txtValue = (txt as TextBox)?.Text; valueStrings[line.GetHashCode()][col] = txtValue; } } SudokuValidator validator = new SudokuValidator(); var isValid = validator.IsValid(valueStrings); if (!isValid) { MessageBox.Show("Não é válido"); } else { MessageBox.Show("Válido"); } }
public void InputRowsNumberShouldBeEqual9() { SudokuValidator sValidator = new SudokuValidator(this.Path); sValidator.Set2DNumericArray(); Assert.IsTrue(sValidator.InputRowsNumberValid()); }
public void CheckSudoku_Check_elements_UNICITY_FirstLine_has_repeating_Elements() { //Given byte[][] square = { new byte[] { 1, 1 }, new byte[] { 3, 4 } }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public void CheckSudoku_Check_Elements_Line_Integrity_for_2x2_Square() { //Given byte[][] square = { new byte[] { 1, 3 }, new byte[] { 2, 1 } }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public void NrElemSudoku_Validator_ShouldReturn_False() { var sudoku = new SudokuValidator(new int[][] { new int[] { 4, 3, 5, 2, 6, 9, 7, 8, 1 }, new int[] { 6, 8, 2, 5, 7, 1, 4, 9, 3 }, new int[] { 1, 9, 7, 8, 3, 4, 5, 6, 2 }, new int[] { 8, 2, 6, 1, 9, 5, 3, 4, 7 }, new int[] { 3, 7, 4, 6, 8, 2, 9, 1, 5 }, new int[] { 9, 5, 1, 7, 4, 3, 6, 2, 8 }, new int[] { 5, 1, 9, 3, 2, 6, 8, 7, 4 }, new int[] { 2, 4, 8, 9, 5, 7, 1, 3, 100 }, new int[] { 7, 6, 3, 4, 1, 8, 2, 5, 9 } }); Assert.False(sudoku.IsValid()); }
public static void resolveMonoThread(int[,] arraySudoku) { SudokuValidator sudokuValidator = new SudokuValidator(); bool resultMulti = sudokuValidator.validateSudoku(arraySudoku); if (resultMulti) { Console.WriteLine("Le sudoku est juste"); } else { Console.WriteLine("Le sudoku est faux"); } }
public void CheckSudoku_Check_elements_UNICITY_Elements_Repeat_on_Coloumn() { //Given byte[][] square = { new byte[] { 1, 2 }, new byte[] { 1, 2 } }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public ActionResult <SudokuPuzzleDTO> Solve(SudokuPuzzleDTO puzzle) { ISudokuValidator validator = new SudokuValidator(); ISudokuSolver solver = new SudokuSolver(puzzle.Puzzle, validator); ISudokuPuzzle solved = solver.Solve(); SudokuPuzzleDTO puzzleDTO = new SudokuPuzzleDTO() { Puzzle = solved.ToString(), Seed = puzzle.Seed }; return(puzzleDTO); }
public void CheckSudoku_Check_Elements_Integrity_for_Larger_Square() { //Given byte[][] square = { new byte[] { 1, 2, 3, 4 }, new byte[] { 2, 3, 1, 4 }, new byte[] { 1, 2, 3, 4 }, new byte[] { 15, 2, 3, 4 } }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public void CheckSudoku_SimpleCase_4x4_Square_InnerBlock_Repetition() { //Given byte[][] square = { new byte[] { 1, 2, 3, 4 }, new byte[] { 2, 1, 4, 3 }, new byte[] { 3, 4, 1, 2 }, new byte[] { 4, 3, 2, 1 }, }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public void CheckSudoku_Elements_Repeat_On_Column_FullSize_Square() { //Given byte[][] square = { new byte[] { 4, 3, 5, 2, 6, 9, 7, 8, 1 }, new byte[] { 6, 8, 2, 5, 7, 1, 4, 9, 3 }, new byte[] { 1, 9, 7, 8, 3, 4, 5, 6, 2 }, new byte[] { 8, 2, 6, 1, 9, 5, 3, 4, 7 }, new byte[] { 3, 7, 4, 6, 8, 2, 9, 1, 5 }, new byte[] { 9, 5, 1, 7, 4, 3, 6, 2, 4 }, new byte[] { 5, 1, 9, 3, 2, 6, 8, 7, 8 }, new byte[] { 2, 4, 8, 9, 5, 7, 1, 3, 6 }, new byte[] { 2, 6, 3, 4, 1, 8, 2, 7, 9 }, }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public void CheckSudoku_Check_Elements_Integrity_for_FULLSIZE_square() { //Given byte[][] square = { new byte[] { 9, 2, 6, 1, 7, 8, 5, 4, 3 }, new byte[] { 4, 9, 3, 6, 5, 2, 1, 9, 8 }, new byte[] { 8, 5, 1, 9, 4, 3, 6, 2, 7 }, new byte[] { 6, 8, 5, 2, 3, 1, 9, 7, 4 }, new byte[] { 7, 3, 4, 8, 9, 5, 2, 6, 1 }, new byte[] { 2, 1, 9, 4, 6, 7, 8, 3, 5 }, new byte[] { 5, 6, 8, 7, 2, 4, 3, 1, 9 }, new byte[] { 3, 4, 2, 5, 1, 9, 7, 8, 6 }, new byte[] { 12, 9, 7, 3, 8, 6, 4, 5, 2 } }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
public void CheckSudoku_Check_elements_UNICITY_For_FULLSCALE_square() { //Given byte[][] square = { new byte[] { 4, 3, 5, 2, 6, 9, 7, 8, 1 }, new byte[] { 6, 8, 2, 5, 7, 1, 4, 9, 3 }, new byte[] { 1, 9, 7, 8, 3, 4, 5, 6, 2 }, new byte[] { 8, 2, 6, 1, 9, 5, 3, 4, 7 }, new byte[] { 3, 7, 4, 6, 8, 2, 9, 1, 5 }, new byte[] { 9, 5, 1, 7, 4, 3, 6, 2, 8 }, new byte[] { 5, 1, 9, 3, 2, 6, 8, 7, 4 }, new byte[] { 2, 4, 8, 9, 5, 7, 1, 3, 6 }, new byte[] { 7, 6, 3, 4, 1, 8, 2, 5, 9 }, }; //When var validator = new SudokuValidator(square); //Then Assert.True(validator.CheckSudoku()); }
public void CheckSudoku_Check_elements_UNICITY_Elements_Repeat_Inside_First_Block() { //Given byte[][] square = { new byte[] { 9, 2, 6, 1, 7, 8, 5, 4, 3 }, new byte[] { 4, 9, 3, 6, 5, 2, 1, 9, 8 }, new byte[] { 8, 5, 1, 9, 4, 3, 6, 2, 7 }, new byte[] { 6, 8, 5, 2, 3, 1, 9, 7, 4 }, new byte[] { 7, 3, 4, 8, 9, 5, 2, 6, 1 }, new byte[] { 2, 1, 9, 4, 6, 7, 8, 3, 5 }, new byte[] { 5, 6, 8, 7, 2, 4, 3, 1, 9 }, new byte[] { 3, 4, 2, 5, 1, 9, 7, 8, 6 }, new byte[] { 1, 9, 7, 3, 8, 6, 4, 5, 2 } }; //When var validator = new SudokuValidator(square); //Then Assert.False(validator.CheckSudoku()); }
static void Main(string[] args) { int[][] field = new int[][] { new int[] { 5, 3, 4, 6, 7, 8, 9, 1, 2 }, new int[] { 6, 7, 2, 1, 9, 5, 3, 4, 8 }, new int[] { 1, 9, 8, 3, 4, 2, 5, 6, 7 }, new int[] { 8, 5, 9, 7, 6, 1, 4, 2, 3 }, new int[] { 4, 2, 6, 8, 5, 3, 7, 9, 1 }, new int[] { 7, 1, 3, 9, 2, 4, 8, 5, 6 }, new int[] { 9, 6, 1, 5, 3, 7, 2, 8, 4 }, new int[] { 2, 8, 7, 4, 1, 9, 6, 3, 5 }, new int[] { 3, 4, 5, 2, 8, 6, 1, 7, 9 }, }; bool isValid = SudokuValidator.ValidateSolution(field); Console.WriteLine("Press any button to continue."); Console.ReadLine(); }
static void Main(string[] args) { if (args.Length > 0 && !String.IsNullOrEmpty(args[0])) { if (File.Exists(args[0].ToString())) { using (SudokuValidator validator = new SudokuValidator()) { validator.InputFile = args[0].ToString(); Console.WriteLine(validator.IsValidSudoku()); } } else { Console.WriteLine("Input file not found."); } } else { Console.WriteLine("An input file was expected.\n\nUsage:\n\tSudokuTester.exe <path_to_your_input_file>"); } Console.ReadKey(); }
public bool IsValidSudoku(char[][] board) { var validator = new SudokuValidator(); for (int i = 0; i < board.Length; i++) { for (int j = 0; j < board[i].Length; j++) { if (board[i][j] == '.') { continue; } var cellValue = CharToInt(board[i][j]); if (!validator.AddCellValueAndReturnIfValid(cellValue, i, j)) { return(false); } } } return(true); }
public void MakeInstance() { SudokuValidator validator = new SudokuValidator(); }
static void Main(string[] args) { SudokuSolver ss = new SudokuSolver(); SudokuFieldBuilder sudokuFieldBuilder = new SudokuFieldBuilder(); SudokuValidator sudokuValidator = new SudokuValidator(); var rang = 9; var mass = sudokuFieldBuilder.InitField().Mix().Build().Clone() as int?[, ]; var gameMass = sudokuFieldBuilder.SetEmptyCount(35).DeleteNumbers().Build().Clone() as int?[, ]; Console.WindowWidth = 200; for (int i = 0; i < rang; i++) { for (int j = 0; j < rang; j++) { Console.Write((mass[i, j] ?? 0) + " "); } Console.WriteLine(); } Console.WriteLine(); ss.Solve(gameMass); Console.WriteLine(); game: for (int i = 0; i < rang; i++) { for (int j = 0; j < rang; j++) { Console.Write(gameMass[i, j] + " "); } Console.WriteLine(); } Console.Write("Row:"); var row = Convert.ToInt32(Console.ReadLine()); Console.Write("Column:"); var column = Convert.ToInt32(Console.ReadLine()); Console.Write("Value:"); var value = Convert.ToInt32(Console.ReadLine()); try { sudokuValidator.Validate(gameMass, new CellModel { Column = column, Row = row, Value = value }); gameMass[row, column] = value; } catch (AlreadyExistException ex) { Console.WriteLine(ex.Message + " " + ex.Cell.ToString()); } goto game; }
private IEnumerable <SudokuSolver> BranchSolverIterator(Definition.Sudoku sudoku) { int seatCount = -1; IEnumerable <Definition.Element> branchBasedElements = null; for (int i = 2; i <= SEAT_UPPER_BOUND; i++) { if (tryFindBranchBasedElements(sudoku, i, out branchBasedElements)) { seatCount = i; break; } } if (seatCount < 0) { yield break; } var branchBasedEmptyElements = branchBasedElements.NotValued(); var remainderValues = branchBasedElements .Values() .SudokuExcept(); foreach (var values in new HeapFullPermutationEnumerable <int>(remainderValues)) { var branchSudoku = sudoku.Copy(); var branchElements = branchBasedEmptyElements .Select(item => branchSudoku.Grids[item.GridIndex].Elements[item.Index]); using (var validator = new SudokuValidator(branchSudoku)) { using (var valueIterator = values.GetEnumerator()) using (var elementIterator = branchElements.GetEnumerator()) { while (valueIterator.MoveNext() && elementIterator.MoveNext()) { var currentElement = elementIterator.Current; var currentValue = valueIterator.Current; //var fillingLog = string.Format("{0, -30}: ({1}, {2}) - {3}", // "new branch", // currentElement.GridIndex + 1, // currentElement.Index + 1, // currentValue); currentElement.SetValue(currentValue); if (validator.HasFailed) { break; } //else // Console.WriteLine(fillingLog); } } if (!validator.HasFailed) { yield return(new SudokuSolver(branchSudoku)); } } } }
public void SetUp() { //arrange sudo = new SudokuValidator(); }
public void AllDigitAreDifferentForEach3x3() { SudokuValidator sValidator = new SudokuValidator(this.Path); Assert.IsTrue(sValidator.SudokuInputValid() && sValidator.Check3x3()); }
public void TearDown() { sudo = null; }
public void AllInputRowsLengthShouldBeEqual9() { SudokuValidator sValidator = new SudokuValidator(this.Path); Assert.IsTrue(sValidator.InputRowsLengthValid()); }