Adding a Scala solution to problem 2