Version 1 of solution for problem 2