Skip to content

Instantly share code, notes, and snippets.

@serdardalgic
Created August 29, 2012 10:28
Show Gist options
  • Select an option

  • Save serdardalgic/3510050 to your computer and use it in GitHub Desktop.

Select an option

Save serdardalgic/3510050 to your computer and use it in GitHub Desktop.
from itertools import permutations
n = 8
cols = range(n)
for vec in permutations(cols):
if n == len(set(vec[i]+i for i in cols)) \
== len(set(vec[i]-i for i in cols)):
print ( vec )
def board(vec):
'''Translate column positions to an equivalent chess board.
>>> board([0, 4, 7, 5, 2, 6, 1, 3])
Q-------
----Q---
-------Q
-----Q--
--Q-----
------Q-
-Q------
---Q----
'''
for col in vec:
s = ['-'] * len(vec)
s[col] = 'Q'
print ''.join(s)
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment