Created
November 30, 2020 17:17
-
-
Save md2perpe/972c9f1a6fbfd30db3a151c75f7a8499 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Maximum unattacked squares | |
def attacked_from_square(r, c): | |
attacked = set([]) | |
for i in range(5): | |
attacked.add((r,i)) | |
attacked.add((i,c)) | |
if 0<=r+i<5 and 0<=c+i<5: | |
attacked.add((r+i,c+i)) | |
if 0<=r+i<5 and 0<=c-i<5: | |
attacked.add((r+i,c-i)) | |
if 0<=r-i<5 and 0<=c+i<5: | |
attacked.add((r-i,c+i)) | |
if 0<=r-i<5 and 0<=c-i<5: | |
attacked.add((r-i,c-i)) | |
return attacked | |
def count_unattacked(board): | |
attacked = set([]) | |
for i in board: | |
attacked.update(attacked_from_square(i//5, i%5)) | |
return 25 - len(attacked) | |
import itertools | |
max_ = 0 | |
for board in itertools.combinations(range(25), 5): | |
new = count_unattacked(board) | |
if new > max_: | |
max_ = new | |
print(f"{max_}: {board}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment