finished problem2 of homework 1