Solved problem 33 in scala