[Haskell-cafe] Re: Slower with ByteStrings?

apfelmus apfelmus at quantentunnel.de
Sat May 26 18:11:52 EDT 2007


Jason Dagit wrote:
> Given a word, find all the words in the dictionary which can be made
> from the letters of that word.  A letter can be used at most as many
> times as it appears in the input word.  So, "letter" can only match
> words with 0, 1, or 2 t's in them.

I don't know about the ByteString thing but how about a general speedup?

   frequencies = map (\x -> (head x, length x)) . group . sort
   superset xs = \ys -> let y = frequencies ys in
        length y == lx &&
        and (zipWith (\(c,i) (d,j) -> c == d && i >= j) x y)
      where
      x  = frequencies xs
      lx = length x

   main = interact $ unlines . filter ("ubuntu" `superset`) . lines

Regards,
apfelmus



More information about the Haskell-Cafe mailing list