-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin sketching out the solver algorithm
- Loading branch information
Charles Anderson
authored and
Charles Anderson
committed
Dec 27, 2019
1 parent
e33ccfa
commit 1965eef
Showing
8 changed files
with
121 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea/ | ||
cmd/* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
# sudokusolver | ||
Golang program for solving a Sudoku | ||
|
||
Implemented from the Backtracking technique described here: https://en.wikipedia.org/wiki/Sudoku_solving_algorithms#Backtracking | ||
|
||
**Dependencies** | ||
|
||
go get github.com/stretchr/testify/assert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
board "sudokusolver/pkg/boards" | ||
"sudokusolver/pkg/cells" | ||
"sudokusolver/pkg/solvers" | ||
) | ||
|
||
func main() { | ||
fmt.Println("Sudoku solvers") | ||
|
||
var easySudoku = []int{ | ||
0, 0, 3, 0, 2, 0, 6, 0, 0, | ||
9, 0, 0, 3, 0, 5, 0, 0, 1, | ||
0, 0, 1, 8, 0, 6, 4, 0, 0, | ||
|
||
0, 0, 8, 1, 0, 2, 9, 0, 0, | ||
7, 0, 0, 0, 0, 0, 0, 0, 0, | ||
0, 0, 6, 7, 0, 8, 2, 0, 0, | ||
|
||
0, 0, 2, 6, 0, 9, 5, 0, 0, | ||
8, 0, 0, 2, 0, 3, 0, 0, 0, | ||
0, 0, 5, 0, 1, 0, 3, 0, 0, | ||
} | ||
|
||
board := board.NewBoard(cells.NewFactory(), easySudoku) | ||
|
||
solvedBoard := solvers.Solve(board) | ||
fmt.Println(solvedBoard.CheckComplete()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package solvers | ||
|
||
import ( | ||
"fmt" | ||
"sudokusolver/pkg/boards" | ||
"sudokusolver/pkg/cells" | ||
) | ||
|
||
func checkValid(board boards.Board, index int) bool { | ||
//check horizontal | ||
//check vertical | ||
//check 3x3 squares | ||
return true | ||
} | ||
|
||
func checkHorizonal(board boards.Board, index int) bool { | ||
return true | ||
} | ||
|
||
func checkVertical(board boards.Board, index int) bool { | ||
return true | ||
} | ||
|
||
func checkSquares(board boards.Board, index int) bool { | ||
return true | ||
} | ||
|
||
|
||
func Solve(board boards.Board) boards.Board { | ||
fmt.Println(board.GetCell(0).GetCellType()) | ||
i := 0 | ||
for i < boards.CELL_COUNT { | ||
fmt.Print(i, ",") | ||
checkValid(board, i) | ||
if board.GetCell(i).GetCellType() == cells.PRESET_CELL_TYPE { | ||
//skip over preset cells (they're not setable) | ||
i++ | ||
continue | ||
} else if board.GetCell(i).GetCellValue() == cells.MAX_CELL_VALUE { | ||
//We've tried all the valid values for this cell, time to backtrack | ||
board.GetCell(i).SetCellValue(0) | ||
for { | ||
i-- | ||
if board.GetCell(i).GetCellType() == cells.SETTABLE_CELL_TYPE { | ||
continue | ||
} | ||
} | ||
} else { | ||
board.GetCell(i).SetCellValue(board.GetCell(i).GetCellValue() + 1) | ||
i++ | ||
} | ||
//Otherwise | ||
} | ||
|
||
return board | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestCheckValid(t *testing.T) { | ||
t.Skip("Skipped - implement TestCheckValid when function implemented") | ||
} | ||
|
||
func TestCheckHorizonal(t *testing.T) { | ||
t.Skip("Skipped - implement TestCheckHorizonal when function implemented") | ||
} | ||
|
||
func TestCheckVertical(t *testing.T) { | ||
t.Skip("Skipped - implement TestCheckVertical when function implemented") | ||
} | ||
|
||
func TestCheckSquares(t *testing.T) { | ||
t.Skip("Skipped - implement TestCheckSquares when function implemented") | ||
} | ||
|
||
func TestSolve(t *testing.T) { | ||
t.Skip("Skipped - implement TestSolve when function implemented") | ||
} |