problem 8 implemented the solution which I could not figure out myself