finished problem 2.4 for cs262