Last active
April 17, 2018 19:57
-
-
Save obelisk68/5c392b0b99dbbe3b667d493b8765f926 to your computer and use it in GitHub Desktop.
15 queen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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