Iterative and recursive solution to the ball game