def evalNQueens(individual):
 size = len(individual)
 left_diagonal = ([0] * ((2 * size) - 1))
 right_diagonal = ([0] * ((2 * size) - 1))
 for i in range(size):
  left_diagonal[(i + individual[i])] += 1
  right_diagonal[(((size - 1) - i) + individual[i])] += 1
 sum_ = 0
 for i in range(((2 * size) - 1)):
  if (left_diagonal[i] > 1):
   sum_ += (left_diagonal[i] - 1)
  if (right_diagonal[i] > 1):
   sum_ += (right_diagonal[i] - 1)
 return (sum_,)

def evalNQueens ( individual ) : size = len ( individual ) left_diagonal = ( [ 0 ] * ( ( 2 * size ) - 1 ) ) right_diagonal = ( [ 0 ] * ( ( 2 * size ) - 1 ) ) for i in range ( size ) : left_diagonal [ ( i + individual [ i ] ) ] += 1 right_diagonal [ ( ( ( size - 1 ) - i ) + individual [ i ] ) ] += 1 sum_ = 0 for i in range ( ( ( 2 * size ) - 1 ) ) : if ( left_diagonal [ i ] > 1 ) : sum_ += ( left_diagonal [ i ] - 1 ) if ( right_diagonal [ i ] > 1 ) : sum_ += ( right_diagonal [ i ] - 1 ) return ( sum_ , )
evaluation function for the n-queens problem .