Completed assignment.

Initial version of the completed assignment.
This contains an implementation of the two functions together with
comments.