Problem 14 solved (Scala)