/eightqueen.py Secret
Last active
August 29, 2015 14:25
Revisions
-
3rogue revised this gist
Jul 26, 2015 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,5 @@ def OK(s): solutions = [c for c in cols if OK(c)] for i,s in enumerate(solutions,1): print i,":",s -
3rogue created this gist
Jul 26, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ from itertools import permutations as perm # (1, 5, 8, 6, 3, 7, 2, 4)表示棋子位置:i.imgbox.com/VHrKYxDG.png cols = perm(range(1,9)) #所有可能a88=40320 # 保证对角线 def OK(s): sl = set(r-c for r,c in enumerate(s)) # y=x bs = set(r+c for r,c in enumerate(s)) # y=-x return len(sl) == len(bs) == 8 solutions = [c for c in cols if OK(c)] for i,s in enumerate(solutions,1): print i,":",s