Solve problem 19 using Scala.