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 |
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 ( |
||
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) |
|||
) |
|||
) |
|||
), L |
), L |
||
)$ |
)$ |
||
Queens(8);length(%);</syntaxhighlight> |
Queens(8);length(%);</syntaxhighlight> |