Fixed problem 38 in Scala