Add scala solution.

Mostly taken from Odersky's solution.