second programming assignment.  cache potentially time-consuming computations