[Haskell-cafe] A tale of Project Euler
Sebastian Sylvan
sebastian.sylvan at gmail.com
Wed Nov 28 07:28:57 EST 2007
On Nov 28, 2007 12:12 PM, Kalman Noel <kalman.noel at bluebottle.com> wrote:
> Sebastian Sylvan:
> > primes :: [Integer]
> > primes = 2 : filter (null . primeFactors) [3,5..]
> >
> > primeFactors :: Integer-> [Integer]
> > primeFactors n = factor n primes
> > where
> > factor m (p:ps) | p*p > m = []
> > | m `mod` p == 0 = p : factor (m `div` p) (p:ps)
> > | otherwise = factor m ps
>
> Your definition gives a strange meaning to primeFactors. I'd want that for all
> n, product (primeFactors n) == n. I think this law holds for the code posted
> by Olivier.
Yes you're right. That is property should clearly hold.
--
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862
More information about the Haskell-Cafe
mailing list