Adding solution for exercise 5.
Adding the 'official solutions' for reference.