Solve problem 25 using Scala.