Skip to content

Instantly share code, notes, and snippets.

@bbrt3
Created March 9, 2022 22:14
Show Gist options
  • Save bbrt3/ecaf02cbfed6ced3f07348bc065e9e47 to your computer and use it in GitHub Desktop.
Save bbrt3/ecaf02cbfed6ced3f07348bc065e9e47 to your computer and use it in GitHub Desktop.
Python
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