8 queens algorithm

Revision en2, by I_love_Eva_Green, 2019-04-13 07:08:40

Hi. In the college we are looking at two basic examples of backtracking (sudoku and n-queens) and a question arose: How program the algorithm of the 8 queens in a non-recursive way?

more specifically it must be done through a stack or through a queue counting the steps to reach the solution.

My problem is born with the code they give us and with the algorithm itself (here). I understand that du and dd are the main diagonals but I do not understand the line 16... (specifically du [c + 7 -r]) where that seven comes from(should not move one square per diagonal?).

Tags #backtracking, #algorithms

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English I_love_Eva_Green 2019-04-13 07:08:40 459 Tiny
en1 English I_love_Eva_Green 2019-04-13 04:50:00 207 Initial revision (published)