Recca Chao 的 gitHub page

推廣網站開發,包含 Laravel 和 Kotlin 後端撰寫、自動化測試、讀書心得等。Taiwan Kotlin User Group 管理員。

View on GitHub

Hi, here’s your problem today. This problem was recently asked by Microsoft:

N-Queens is the problem where you find a way to put n queens on a nxn chess board without them being able to attack each other. Given an integer n, return 1 possible solution by returning all the queen’s position.

Here’s an example and some starter code:

def n_queens(n):

Fill this in.

print(n_queens(5))

There can be many answers

[(0, 0), (1, 2), (2, 4), (3, 1), (4, 3)]

Q . . . .

. . . Q .

. Q . . .

. . . . Q

. . Q . .