Sid's HW3 solution