P10.scala solved