Problem 19 (Scala, imperative)