solves problem 6
solves problem 7
solves problem 8