working algorithm, about 20 generations