Esempio n. 1
0
func BenchmarkGetSolutions(b *testing.B) {
	for i := 0; i < b.N; i++ {
		var solution_list []sudoku.Sudoku
		sample_sudoku := sudoku.InitSudoku(sample_board)
		sudoku.GetSolutions(&sample_sudoku, &solution_list)
	}
}
Esempio n. 2
0
func main() {
	var input = [9][9]int{
		{0, 7, 8, 1, 0, 0, 0, 2, 0},
		{1, 0, 0, 0, 6, 2, 0, 0, 3},
		{5, 0, 0, 0, 9, 0, 0, 0, 0},
		{8, 0, 0, 0, 0, 0, 4, 0, 6},
		{0, 6, 1, 0, 7, 0, 0, 9, 0},
		{0, 9, 0, 0, 0, 0, 3, 0, 0},
		{0, 0, 0, 5, 0, 4, 2, 0, 7},
		{6, 0, 0, 0, 8, 0, 0, 3, 0},
		{0, 5, 0, 7, 0, 0, 9, 0, 0}}
	_ = input
	var input2 = [9][9]int{
		{8, 0, 0, 0, 0, 1, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 7, 0, 0, 0, 5, 0},
		{0, 5, 0, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 0, 0, 9, 0, 0, 0},
		{0, 0, 0, 0, 0, 0, 0, 0, 0},
		{9, 0, 7, 0, 0, 0, 0, 0, 0},
		{0, 0, 0, 8, 0, 0, 3, 2, 0},
		{2, 0, 0, 0, 0, 0, 0, 0, 0}}
	_ = input2
	var output = [9][9]int{
		{3, 7, 8, 1, 4, 5, 6, 2, 9},
		{1, 4, 9, 8, 6, 2, 7, 5, 3},
		{5, 2, 6, 3, 9, 7, 1, 4, 8},
		{8, 3, 5, 9, 2, 1, 4, 7, 6},
		{2, 6, 1, 4, 7, 3, 8, 9, 5},
		{7, 9, 4, 6, 5, 8, 3, 1, 2},
		{9, 8, 3, 5, 1, 4, 2, 6, 7},
		{6, 1, 7, 2, 8, 9, 5, 3, 4},
		{4, 5, 2, 7, 3, 6, 9, 8, 1}}

	// Init the input sudoku
	board := sudoku.InitSudoku(input)
	_ = board
	// Init the solution sudoku
	solution := sudoku.InitSudoku(output)
	_ = solution
	fmt.Println(board)

	var solution_list []sudoku.Sudoku
	sudoku.GetSolutions(&board, &solution_list)
	fmt.Println(sudoku.CheckSingle(&board))
	var generate = sudoku.GenerateSudoku()
	var sol_num, _ = sudoku.CheckSingle(&generate)
	fmt.Println("Sudoku generated with number of solution:", sol_num, "unassign block: ", sudoku.CountEmptyBlockWithMultiVal(generate))
	fmt.Println(generate)

	sudoku.BacktrackSolve(&generate)
	fmt.Println(generate)
}
Esempio n. 3
0
func TestGetSolutions(t *testing.T) {
	sample_sudoku := sudoku.InitSudoku(sample_board)
	single_sudoku_solution := sudoku.InitSudoku(sample_board_solution)
	var solution_list []sudoku.Sudoku
	sudoku.GetSolutions(&sample_sudoku, &solution_list)
	if len(solution_list) != 1 {
		t.Errorf("GetSolutions dont give any solution or more give more than 1")
	}
	for i, r := range single_sudoku_solution {
		for j, a := range r {
			if solution_list[0][i][j].Val != a.Val {
				t.Errorf("RecursiveSolve give wrong solution at block %v", 9*i+j)
			}
		}
	}
}