Solved problem 36 in scala