Adding solution for problem 31