N-queens problem: Difference between revisions

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


Queens(8);length(%);</syntaxhighlight>
Queens(8);length(%);</syntaxhighlight>