Exercise 3.25, naive version
Exercise 3.25, tail recursive version