commit d11db280c11eaa84e55d29115b229c557de0e369 Author: Sacha Ligthert Date: Thu Dec 5 17:46:09 2024 +0100 Initial comit. Playing around a bit. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..14c7d55 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module gitea.ligthert.net/golang/sudoku-funpark + +go 1.23.3 diff --git a/main.go b/main.go new file mode 100644 index 0000000..e8a440e --- /dev/null +++ b/main.go @@ -0,0 +1,74 @@ +package main + +import ( + "fmt" + "strconv" +) + +func main() { + blocks := generate_blocks() + fmt.Println(len(blocks)) + fmt.Println(blocks[0]) +} + +func 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 + +} + +// counter: 123456789 +// 1st Digit: 1 (49) +// 2nd Digit: 2 (50) +// 3rd Digit: 3 (51) +// 4th Digit: 4 (52) +// 5th Digit: 5 (53) +// 6th Digit: 6 (54) +// 7th Digit: 7 (55) +// 8th Digit: 8 (56) +// 9th Digit: 9 (57) + +// 362880 + +// 1 2 3 +// 4 5 6 +// 7 8 9 + +// 1: 1 2 3 4 7 +// 2: 1 2 3 5 8 +// 3: 1 2 3 6 9 +// 4: 1 4 5 6 7 +// 5: 2 4 5 6 8 +// 6: 3 4 5 6 9 +// 7: 1 4 7 8 9 +// 8: 2 5 7 8 9 +// 9: 3 6 7 8 9