wrote code to find optimal number of iterations and return the results