problem 3 for scala