N Queen Puzzle Backtracking Algorithm 1. Starting from first row, loop through all the positions in this row, if could find a safe position, mark it and move forward to next row. 2. If you can a safe position in the next row, keep moving forward. If this finally leads to a solution, save it. Otherwise transverse back to previous row to look for other possible safe positions 3. Repeat until we have looped through all positions type Board struct { field [][]int} type Boards []Board Shuo Zhao
Independent Solutions N=4 Independent Solutions N=4 Solutions N=5, 6, 7, 8 Solutions N Ind All
Nonstandard Board ShapestandardcolumnDonut Attacking conditionsx=i; y=j; abs(x-i)=abs(j-y) x=i; y=j; abs(x-i)=abs(j-y) abs(x-i)=abs(j+n-y) abs(x-i)=abs(j-n-y) x=i; y=j; abs(x-i)=abs(j-y) abs(x-i)=abs(j+n-y) abs(x-i)=abs(j-n-y) abs(x+n-i)=abs(j-y) abs(x-n-i)=abs(j-y) Higher Dimensional Board (3d as example) abs(x-i)=abs(y-j)=abs(z-k) (3dimensional diagonal) if x=i (yz plane): y=j; z=k; (1dimensional); abs(y-j)=abs(z-k) (2dimensional) if y=i (xz plane): x=i; z=k; (1dimensional); abs(x-i)=abs(z-k) (2dimensional) if z=k (xy plane): y=j; x=i; (1dimensional); abs(y-j)=abs(x-i) (2dimensional) if x!=i&& y!=i&& z!=k (xyz space): abs(x-i)=abs(y-j)=abs(z-k) (3dimensional) Jeremiah Barr and Shrisha Rao, Department of Computer Science, Mount Mercy College, IA _2004/Barr.pdf N=4