check next node

master
ironbound 2022-02-05 11:45:14 +01:00
parent 8ced2a930d
commit 40d9640271
1 changed files with 29 additions and 4 deletions

33
main.go
View File

@ -1,15 +1,40 @@
package main
import "fmt"
var (
// 4x4 board with node counts
board = map[int]int{
11: 2, 12: 3, 13: 3, 14: 3,
21: 1, 22: 4, 23: 5, 24: 9,
31: 0, 32: 2, 33: 2, 34: 4,
41: 0, 42: 1, 43: 3, 44: 0,
10: 2, 11: 3, 12: 3, 13: 3,
20: 1, 21: 4, 22: 5, 23: 9,
30: 0, 31: 2, 32: 2, 33: 4,
40: 0, 41: 1, 42: 3, 43: 0,
}
)
func main() {
q := make(chan int, 4)
// board[p]
p := 22
// walk and find nodes
if board[p-11] != 0 { // NW
q <- (p - 11)
}
if board[p-9] != 0 { // NE
q <- (p - 9)
}
if board[p+9] != 0 { // SW
q <- (p + 9)
}
if board[p+11] != 0 { // SE
q <- (p + 11)
}
close(q)
// Get valid nodes
for n := range q {
fmt.Println(n)
}
}