Add Scala solution for problem 2.