Solved problems 29,30 and 31 in scala