Solved problem 26 in scala