Problem Set 6, question 2 code