Explorar o código

Initial comit. Playing around a bit.

Sacha Ligthert hai 1 ano
achega
d11db280c1
Modificáronse 2 ficheiros con 77 adicións e 0 borrados
  1. 3 0
      go.mod
  2. 74 0
      main.go

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module gitea.ligthert.net/golang/sudoku-funpark
+
+go 1.23.3

+ 74 - 0
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