Fixed fitness function to handle strings of different lengths