#!python3 #encoding:mbcs from itertools import ( combinations, permutations, product, ) def main(): board_size = 10 n = 0 for y_values in permutations(range(board_size), board_size): queens = set((x, y) for x, y in zip(range(board_size), y_values)) if all(((x0 - y0) != (x1 - y1) and (x0 + y0) != (x1 + y1)) for (x0, y0), (x1, y1) in combinations(queens, 2)): n += 1 print(n) if __name__ == "__main__": main()
特に意味はありません。