N-queens

Write n_queens(n) that returns how many ways n queens can be placed on an n × n board so that no two share a row, column or diagonal.

n_queens(1)  ->  1
n_queens(4)  ->  2
n_queens(8)  ->  92

The point is to practise backtracking with pruning: one queen per row, and three sets that make "is this square attacked" a constant-time check. n_queens(9) is checked, so unpruned search will not do.

def n_queens(n):
    ...