[Haskell-cafe] factorising to prime numbers

ajb at spamcop.net ajb at spamcop.net
Wed Feb 14 23:06:25 EST 2007

G'day all.

Quoting Dougal Stanton <ithika at gmail.com>:

> Is there a better way to turn an integer N and a list of primes
> [p1,p2,p3,...] into powers [c1,c2,c3,...] such that
> N = product [p1^c1, p2^c2, p3^c3, ...]

It depends what you mean by "better".

You can make it more concise by using zip or zipWith:

    product (zipWith (^) ps cs)

If you're after performance, that's another issue entirely.  For
large integers, you're using entirely the wrong algorithm.

Andrew Bromage

More information about the Haskell-Cafe mailing list