My translation of somebody else's Haskell solution to Scala