Skip to content

Instantly share code, notes, and snippets.

@obelisk68
Last active April 17, 2018 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obelisk68/5c392b0b99dbbe3b667d493b8765f926 to your computer and use it in GitHub Desktop.
Save obelisk68/5c392b0b99dbbe3b667d493b8765f926 to your computer and use it in GitHub Desktop.
15 queen
package main
import "fmt"
const num = 15
var count = 0
func get_space(field []int) [num]int {
result := [num]int{}
l := len(field)
for i, queen := range field {
result[queen] = 1
dst := l - i
if a := queen - dst; a >= 0 {result[a] = 1}
if a := queen + dst; a < num {result[a] = 1}
}
return result
}
func solve(field []int) {
if len(field) == num {
count++
} else {
for i, space := range get_space(field) {
if space == 0 { solve(append(field, i)) }
}
}
}
func main () {
solve([]int{})
fmt.Println(count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment