code for hw1 problem 3