Mastering Exercise 1210 from Scheme and the art of programming