Solved problem 54 and 55 in scala