n_generations function

Determine the number of generations