Solved problem 53 in scala