Skip to content

Commit 59fa07c

Browse files
mkhalid1norvig
authored andcommitted
Updated label_queen_conflicts function (#967)
Shortened it, finding conflicts separately and storing them in different variables has no use later in the notebook; so i believe this looks better.
1 parent 4378fb2 commit 59fa07c

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

csp.ipynb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2821,19 +2821,13 @@
28212821
"def label_queen_conflicts(assignment,grid):\n",
28222822
" ''' Mark grid with queens that are under conflict. '''\n",
28232823
" for col, row in assignment.items(): # check each queen for conflict\n",
2824-
" row_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
2825-
" if temp_row == row and temp_col != col}\n",
2826-
" up_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
2827-
" if temp_row+temp_col == row+col and temp_col != col}\n",
2828-
" down_conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
2829-
" if temp_row-temp_col == row-col and temp_col != col}\n",
2824+
" conflicts = {temp_col:temp_row for temp_col,temp_row in assignment.items() \n",
2825+
" if (temp_row == row and temp_col != col\n",
2826+
" or (temp_row+temp_col == row+col and temp_col != col)\n",
2827+
" or (temp_row-temp_col == row-col and temp_col != col)}\n",
28302828
" \n",
28312829
" # Place a 3 in positions where this is a conflict\n",
2832-
" for col, row in row_conflicts.items():\n",
2833-
" grid[col][row] = 3\n",
2834-
" for col, row in up_conflicts.items():\n",
2835-
" grid[col][row] = 3\n",
2836-
" for col, row in down_conflicts.items():\n",
2830+
" for col, row in conflicts.items():\n",
28372831
" grid[col][row] = 3\n",
28382832
"\n",
28392833
" return grid\n",

0 commit comments

Comments
 (0)