Solution for Problem 5
Starting to solve Problem 6