scala solution problem 4