Actually wrote the code part of problem 9