import numpy
numQueens = 8
solutions = []
def board(placed):
for c in placed:
r = ['_ '] * 8
r[c] = '♕ '
print(''.join(r)) # строка из списка
print('-' * 22)
print(placed)
def check(y1, x1, y2, x2):
samev = x1 == x2
sameh = y1 == y2
maind = x1 + y1 == x2 + y2
secondd = x1 - y1 == x2 - y2
return samev or sameh or maind or secondd
def invalid(placed, x2):
for y, x in enumerate(placed):
if check(y, x, len(placed), x2):
return True
def queens(valid, placed):
if len(placed) == numQueens:
solutions.append(placed[:])
return
for y, x in enumerate(valid):
if invalid(placed, x):
continue
placed.append(x)
queens(list(valid[:y]) + list(valid[y+1:]), placed)
placed.pop()
print("a")
a = int(input())
b = int(input())
print(solutions)
queens(range(8), [])
for solution in solutions:
board(solution)
print("Всего решений: ", len(solutions))