How to resolve the algorithm N-queens problem step by step in the Logo programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm N-queens problem step by step in the Logo programming language
Table of Contents
Problem Statement
Solve the eight queens puzzle.
You can extend the problem to solve the puzzle with a board of size NxN. For the number of solutions for small values of N, see OEIS: A000170.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm N-queens problem step by step in the Logo programming language
Source code in the logo programming language
to try :files :diag1 :diag2 :tried
if :files = 0 [make "solutions :solutions+1 show :tried stop]
localmake "safe (bitand :files :diag1 :diag2)
until [:safe = 0] [
localmake "f bitnot bitand :safe minus :safe
try bitand :files :f ashift bitand :diag1 :f -1 (ashift bitand :diag2 :f 1)+1 fput bitnot :f :tried
localmake "safe bitand :safe :safe-1
]
end
to queens :n
make "solutions 0
try (lshift 1 :n)-1 -1 -1 []
output :solutions
end
print queens 8 ; 92
You may also check:How to resolve the algorithm Matrix transposition step by step in the J programming language
You may also check:How to resolve the algorithm Conditional structures step by step in the Batch File programming language
You may also check:How to resolve the algorithm Function composition step by step in the C# programming language
You may also check:How to resolve the algorithm Sum digits of an integer step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Padovan sequence step by step in the Delphi programming language