Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
Add Comment
Please, Sign In to add comment