Problem 4's code for Homework 1