Completed p1 in Scala