Implements problem two of chapter one