Homework code for CS246: HW2 Q4