Solution to problem 5 finished