but i am still confused with the unwinding of the recursive backtracking so can someone explain to me what my code is doing
1. this is not an assignment or project but rather something i am doing during the holidays
and if you think its assignment or project please don't respond.
what i don't understand
my code prints out different solutions close to 90 times, i didn't check if all were different.
but i want it stop after it has found 1 solution to the problem if any.
so can anyone tell me why its printing so many times
since i have the base case if n==size:return board
if you require more explanation me know.
thought i mention that i understand the general concepts of recursion and backtracking to some degree
here is my code
i left out one functions/method call is_Safe(board,x,y) because it looks messy and bad implementation, anyway it returns true or false if the x,y is a safe place to place a queen in according to the board
board=[*8]*8 def solve(board,x,size): if x==size: print" found solution" return board else: for i in range(8):#boar is 8*8 if is_Safe(board,x,i): board[x][i]="Q" solve(board,x+1,size) board[x][i]=0 solve(board,0,8)#place 8 queens on board