A much simpler solution to challenge 22.