Solved problem 40 in scala