גרסה קצת שונה לחידת N מלכות המפורסמת:
בלוח של 5 על 5 יש להציב 3 מלכות ו 5 מלכים מבלי שאף מלך יהיה מאויים (כל מלכה על משבצת שונה)
הקוד שלי
import itertools
board = [[0] * 5] * 5
board_options = []
a = list(range(5))
for i in a:
for j in a:
board_options.append((i, j))
three_queens = list(itertools.combinations(board_options, 3))
new = {}
for point in three_queens:
for q in board_options:
if q not in point:
if q[0] != point[0][0] and q[0] != point[1][0] and q[0] != point[2][0]:
if q[1] != point[0][1] and q[1] != point[1][1] and q[1] != point[2][1]:
if abs(q[0] - point[0][0]) != abs(q[1] - point[0][1]):
if abs(q[0] - point[1][0]) != abs(q[1] - point[1][1]):
if abs(q[0] - point[2][0]) != abs(q[1] - point[2][1]):
if point in new:
new[point] += 1
else:
new[point] = 1
for i, j in new.items():
if j > 4:
print(i, j)
אשמח גם להצעות ייעול או הערות לגבי הקוד שכתבתי