Looks pretty standard. It starts by placing one queen on each square of the 
bottom row, then working up through the
rows trying to put a queen in each column. If it can place a queen it gets 
added as a possible solution.
The always test in the inner loop checks the 'rook' horizontal and then the 
'bishop' diagonal.
The bishop test is a bit tricky, it looks at (x rows up, y columns across 
from a previously placed queen)
If x and y are equal it's on the diagonal.

--
Geoffrey Summerhayes

On Sunday, July 8, 2012 8:00:54 PM UTC-4, Victor Manuel Grijalva Altamirano 
wrote:
>
>
> The next solve the problem of eight Queeen... but i don't undestand 
> it!!!.... can you explain me?
>
> (defun n-queens (n m)
>   (
>         
>     if (= n 1)
>     (loop for x from 1 to m collect (list x))
>         
>         
>     (loop for sol in (n-queens (1- n) m) nconc
>       (loop for col from 1 to m when
>         (loop for row from 0 to (length sol) for c in sol
>               always (and (/= col c)
>                   (/= (abs (- c col)) (1+ row)))
>               finally (return (cons col sol))
>         )
>        collect it
>       )
>      )
>     )
>  )
>
>
>
>
> -- 
> Victor Manuel Grijalva Altamirano
> Universidad Tecnologica de La Mixteca
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/qv0m-4stZdEJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to