Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions csp.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2821,19 +2821,13 @@
"def label_queen_conflicts(assignment,grid):\n",
" ''' Mark grid with queens that are under conflict. '''\n",
" for col, row in assignment.items(): # check each queen for conflict\n",
" row_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
" if temp_row == row and temp_col != col}\n",
" up_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
" if temp_row+temp_col == row+col and temp_col != col}\n",
" down_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
" if temp_row-temp_col == row-col and temp_col != col}\n",
" conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
" if (temp_row == row and temp_col != col\n",
" or (temp_row+temp_col == row+col and temp_col != col)\n",
" or (temp_row-temp_col == row-col and temp_col != col)}\n",
" \n",
" # Place a 3 in positions where this is a conflict\n",
" for col, row in row_conflicts.items():\n",
" grid[col][row] = 3\n",
" for col, row in up_conflicts.items():\n",
" grid[col][row] = 3\n",
" for col, row in down_conflicts.items():\n",
" for col, row in conflicts.items():\n",
" grid[col][row] = 3\n",
"\n",
" return grid\n",
Expand Down