Exercise 5.2, naive recursive version