Quick cleanup

This commit is contained in:
Sacha Ligthert 2025-01-27 20:46:38 +01:00
parent 6241c0b720
commit 51f5d6d77d
2 changed files with 40 additions and 95 deletions

View File

@ -94,5 +94,44 @@ Solution #1:
283597416
```
# Caveats
## Caveats
While this may very well solve all possible Sudoku puzzles (including the one [designed against brute force algorithms](https://en.wikipedia.org/wiki/Sudoku_solving_algorithms)), the blanks in the puzzle, the harder it is, the more possible solutions there are, the more solutions it needs to parse, the longer it takes. As this is a computational heavy program, the more CPU you throw against it the faster it will solve issues.
## Generating your own blocks
To generate your own blocks, you could use the following code:
```go
func (solver *Solver) generate_blocks() []int {
var blocks []int
decvals := [9]int{49, 50, 51, 52, 53, 54, 55, 56, 57}
for counter := 123456789; counter <= 987654321; counter++ {
// Convert number to string ([]byte)
digits := strconv.Itoa(counter)
// Check if every number is only represented only once
var valid bool
valid = true
for decval := range decvals {
var count int
for digit := range digits {
if digits[digit] == byte(decvals[decval]) {
count = count + 1
}
}
if count != 1 {
valid = false
}
}
if valid {
blocks = append(blocks, counter)
}
}
return blocks
}
```

View File

@ -1,94 +0,0 @@
// Processing
func (solver *Solver) routine_row1(index1 int) {
for index2 := range solver.row2s {
go solver.routine_row2(index1, index2)
}
}
func (solver *Solver) routine_row2(index1 int, index2 int) {
for index3 := range solver.row3s {
go solver.routine_row3(index1, index2, index3)
}
}
func (solver *Solver) routine_row3(index1 int, index2 int, index3 int) {
for index4 := range solver.row4s {
go solver.routine_row4(index1, index2, index3, index4)
}
}
func (solver *Solver) routine_row4(index1 int, index2 int, index3 int, index4 int) {
for index5 := range solver.row5s {
go solver.routine_row5(index1, index2, index3, index4, index5)
}
}
func (solver *Solver) routine_row5(index1 int, index2 int, index3 int, index4 int, index5 int) {
for index6 := range solver.row6s {
go solver.routine_row6(index1, index2, index3, index4, index5, index6)
}
}
func (solver *Solver) routine_row6(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int) {
for index7 := range solver.row7s {
go solver.routine_row7(index1, index2, index3, index4, index5, index6, index7)
}
}
func (solver *Solver) routine_row7(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int, index7 int) {
for index8 := range solver.row8s {
go solver.routine_row8(index1, index2, index3, index4, index5, index6, index7, index8)
}
}
func (solver *Solver) routine_row8(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int, index7 int, index8 int) {
for index9 := range solver.row9s {
go solver.routine_row9(index1, index2, index3, index4, index5, index6, index7, index8, index9)
}
}
func (solver *Solver) routine_row9(index1 int, index2 int, index3 int, index4 int, index5 int, index6 int, index7 int, index8 int, index9 int) {
go solver.routineValidator(index1, index2, index3, index4, index5, index6, index7, index8, index9)
}
// blocks.go
func (solver *Solver) generate_blocks() []int {
var blocks []int
decvals := [9]int{49, 50, 51, 52, 53, 54, 55, 56, 57}
for counter := 123456789; counter <= 987654321; counter++ {
// Convert number to string ([]byte)
digits := strconv.Itoa(counter)
// Check if every number is only represented only once
var valid bool
valid = true
for decval := range decvals {
var count int
for digit := range digits {
if digits[digit] == byte(decvals[decval]) {
count = count + 1
}
}
if count != 1 {
valid = false
}
}
if valid {
blocks = append(blocks, counter)
}
}
return blocks
}
// stash.go
func (solver *Solver) print_block(block int) {
digits := strconv.Itoa(block)
fmt.Printf("%c %c %c\n%c %c %c\n%c %c %c\n\n", digits[0], digits[1], digits[2], digits[3], digits[4], digits[5], digits[6], digits[7], digits[8])
}