python solution for problem 29
scala solution for problem 29