Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- sols = []
- def f(k, e):
- if k == 8:
- if e not in sols:
- sols.append(e)
- return True
- candidates = []
- for i in range(8):
- for x, y in e:
- if x == i or abs(y - k) == abs(x - i):
- break
- else:
- candidates.append((i, k))
- if candidates:
- e.append(candidates[randint(0, len(candidates) - 1)])
- res = f(k + 1, e)
- if res:
- return True
- return False
- def main():
- while len(sols) != 92:
- f(0, [])
- for s in sols:
- print(s)
- for x, _ in s:
- print(('-' * x) + '*' + ('-' * (7 - x)))
- main()
Add Comment
Please, Sign In to add comment