Solve problems 2,9 using Scala.