Simple solution for problem 40