This is a problem from an introduction to computer science textbook