diff --git a/csp.ipynb b/csp.ipynb index fcf8b5867..411d6f55c 100644 --- a/csp.ipynb +++ b/csp.ipynb @@ -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",