-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e25a9c1
Showing
2 changed files
with
108 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Sudoku methods | ||
// type Sudoku interface { | ||
// createPuzzle() | ||
// getPuzzle() [9][9]square | ||
// } | ||
|
||
// Puzzle class | ||
type Puzzle struct { | ||
board [9][9]square | ||
} | ||
|
||
type square struct { | ||
val int | ||
x int | ||
y int | ||
box int | ||
} | ||
|
||
func main() { | ||
newBoard := Puzzle{} | ||
fmt.Println(newBoard.createPuzzle()) | ||
} | ||
|
||
func (p Puzzle) createPuzzle() [9][9]square { | ||
var puzzle [9][9]square | ||
for i, row := range puzzle { | ||
for j := range row { | ||
puzzle[i][j].x = j | ||
puzzle[i][j].y = i | ||
if puzzle[i][j].x < 3 { | ||
if puzzle[i][j].y < 3 { | ||
puzzle[i][j].box = 0 | ||
} else if puzzle[i][j].y > 5 { | ||
puzzle[i][j].box = 6 | ||
} else { | ||
puzzle[i][j].box = 3 | ||
} | ||
} else if puzzle[i][j].x > 5 { | ||
if puzzle[i][j].y < 3 { | ||
puzzle[i][j].box = 2 | ||
} else if puzzle[i][j].y > 5 { | ||
puzzle[i][j].box = 8 | ||
} else { | ||
puzzle[i][j].box = 5 | ||
} | ||
} else { | ||
if puzzle[i][j].y < 3 { | ||
puzzle[i][j].box = 1 | ||
} else if puzzle[i][j].y > 5 { | ||
puzzle[i][j].box = 7 | ||
} else { | ||
puzzle[i][j].box = 4 | ||
} | ||
} | ||
} | ||
} | ||
return puzzle | ||
} |
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,44 @@ | ||
package puzzle | ||
|
||
type square struct { | ||
val int | ||
x int | ||
y int | ||
box int | ||
} | ||
|
||
func puzzle() [9][9]square { | ||
var puzzle [9][9]square | ||
for i, row := range puzzle { | ||
for j := range row { | ||
puzzle[i][j].x = j | ||
puzzle[i][j].y = i | ||
if puzzle[i][j].x < 3 { | ||
if puzzle[i][j].y < 3 { | ||
puzzle[i][j].box = 0 | ||
} else if puzzle[i][j].y > 5 { | ||
puzzle[i][j].box = 6 | ||
} else { | ||
puzzle[i][j].box = 3 | ||
} | ||
} else if puzzle[i][j].x > 5 { | ||
if puzzle[i][j].y < 3 { | ||
puzzle[i][j].box = 2 | ||
} else if puzzle[i][j].y > 5 { | ||
puzzle[i][j].box = 8 | ||
} else { | ||
puzzle[i][j].box = 5 | ||
} | ||
} else { | ||
if puzzle[i][j].y < 3 { | ||
puzzle[i][j].box = 1 | ||
} else if puzzle[i][j].y > 5 { | ||
puzzle[i][j].box = 7 | ||
} else { | ||
puzzle[i][j].box = 4 | ||
} | ||
} | ||
} | ||
} | ||
return puzzle | ||
} |