N-queens problem: Difference between revisions

Line 8,850:
<syntaxhighlight lang="maxima">
/* Inspired by code from Python */
Queens(N):=block([K,C,P,V,A,S,L:[]],
C: makelist(K,K,1,N),
P: permutations(C),
for V in P do (
A:if is(N=length(unique(makelist(V[K]+K, K, C))),) then (
S: if is(N=length(unique(makelist(V[K]-K, K, C))),) then (
if is(A=N) and is(S=N) then L: consendcons(V, L)
)
)
), L
)$
 
Queens(8);length(%);</syntaxhighlight>
3

edits