Porting smallestFreeNumber.hs (Haskell solution) to Scala