scala solution for problem 56