added solution for problem 4 (full marks)