Exercise 3.26, naive version
Exercise 3.26, tail recursive version