Problem 1: added Scala solution
Problem 1: a little cleaner