Guest User

Untitled

a guest
Dec 12th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. from itertools import permutations
  2.  
  3. n = 8
  4. cols = range(n)
  5. for vec in permutations(cols):
  6. if n == len(set(vec[i]+i for i in cols)) \
  7. == len(set(vec[i]-i for i in cols)):
  8. print ( vec )
  9.  
  10. def board(vec):
  11. '''Translate column positions to an equivalent chess board.
  12.  
  13. >>> board([0, 4, 7, 5, 2, 6, 1, 3])
  14. Q-------
  15. ----Q---
  16. -------Q
  17. -----Q--
  18. --Q-----
  19. ------Q-
  20. -Q------
  21. ---Q----
  22.  
  23. '''
  24.  
  25. for col in vec:
  26. s = ['-'] * len(vec)
  27. s[col] = 'Q'
  28. print ''.join(s)
  29. print
Add Comment
Please, Sign In to add comment