Solution to problem 18