Solves problem 6