this is the best course of Python I come across till now.
@rishabhsharma39592 жыл бұрын
Explanation should be more elaborate
@chetansainikhurdi6 жыл бұрын
why can't we put at (4, 2) at 8 queen
@jyothyar38004 жыл бұрын
Hi Sir, can we use Greedy algorithm instead of back tracking?
@RA-oo4lj5 жыл бұрын
Very well illustrated.
@arpita06085 жыл бұрын
kichu buhte parlam na
@sayanstrsc.72723 жыл бұрын
😂
@AbhaySingh-dm4zr7 жыл бұрын
please send the complete code too :/
@one_minute_iitian_ai5 жыл бұрын
def initialize(board,n): for key in ['queen','row','col','nwtose','swtone']: board[key]={} for i in range(n): board['queen'][i]=-1 board['row'][i]=0 board['col'][i]=0 for i in range(-(n-1),n): board['nwtose'][i]=0 for i in range(2*n-1): board['swtone'][i]=0 def printboard(board): for row in sorted(board['queen'].keys()): print((row,board['queen'][row])) def free(i,j,board): return(board['row'][i]==0 and board['col'][j]==0 and board['nwtose'][j-i]==0 and board['swtone'][j+i]==0) def addqueen(i,j,board): board['queen'][i]=j board['row'][i]=1 board['col'][j]=1 board['nwtose'][j-i]=1 board['swtone'][j+i]=1 def undoqueen(i,j,board): board['queen'][i]=-1 board['row'][i]=0 board['col'][j]=0 board['nwtose'][j-i]=0 board['swtone'][j+i]=0 def placequeen(i,board): n=len(board['queen'].keys()) for j in range(n): if free(i,j,board): addqueen(i,j,board) if i==n-1: return True else: extendsoln=placequeen(i+1,board) if extendsoln: return True else: undoqueen(i,j,board) else: return False board={} n=int(input("How many Queens? : ")) initialize(board,n) if placequeen(0,board): printboard(board)
@ashokcharan71955 жыл бұрын
@@one_minute_iitian_ai y we want to sorted in printboad function?
@kunjankumar27394 жыл бұрын
@@ashokcharan7195 because board['queen'].keys() won't give the list of keys in sequential order