First solution using Scala!