Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
oorrja
GitHub Repository: oorrja/learntosolveit
Path: blob/master/languages/python/8queens.py
1240 views
1
from itertools import permutations
2
3
# What's the difference between permutations and combinations.
4
# permutations is about arrangements.
5
# combinations is about choosing.
6
7
8
def eight_queens():
9
queens = list(range(8))
10
for pos in permutations(queens):
11
# how many times is the if statement below evaluated?
12
# How does subtracting and addition the position work?
13
if (8 == len(set(pos[i] + i for i in queens))
14
== len(set(pos[i] - i for i in queens))):
15
print(pos)
16
17
18
if __name__ == '__main__':
19
eight_queens()
20
21