Solved Problem #43 in Scala.