Solves Problem 40