Created
March 9, 2022 22:14
-
-
Save bbrt3/ecaf02cbfed6ced3f07348bc065e9e47 to your computer and use it in GitHub Desktop.
Python
This file contains hidden or 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
import numpy as np | |
def canPlace(x2: int, y2: int) -> bool: | |
for x in range(x2): | |
if result[x] == y2 or abs(x - x2) == abs(result[x] - y2): | |
return False; | |
return True; | |
def placeQueens(x: int) -> np.void: | |
for X in range(N): | |
if canPlace(x, X): | |
result[x] = X | |
if (x == N - 1): | |
print(result) | |
placeQueens(x + 1) | |
N: int = 4; | |
result: np.ndarray = np.full(N, -1) | |
placeQueens(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment