2023-07-09 17:42:30 -04:00
|
|
|
/* Inspired by code from Python */
|
2023-07-18 13:51:12 -07:00
|
|
|
Queens(N):=block([K,C,P,V,L:[]],
|
2023-07-09 17:42:30 -04:00
|
|
|
C: makelist(K,K,1,N),
|
|
|
|
|
P: permutations(C),
|
|
|
|
|
for V in P do (
|
2023-07-18 13:51:12 -07:00
|
|
|
if is(N=length(unique(makelist(V[K]+K, K, C)))) then (
|
|
|
|
|
if is(N=length(unique(makelist(V[K]-K, K, C)))) then (
|
|
|
|
|
L: endcons(V, L)
|
|
|
|
|
)
|
|
|
|
|
)
|
2023-07-09 17:42:30 -04:00
|
|
|
), L
|
|
|
|
|
)$
|
|
|
|
|
|
|
|
|
|
Queens(8);length(%);
|