[Haskell-cafe] Prime numbers
Robert Dockins
robdockins at fastmail.fm
Tue Dec 20 11:25:09 EST 2005
-divides a b = (mod a b == 0)
+divides a b = (mod b a == 0)
On Dec 20, 2005, at 11:09 AM, Daniel Carrera wrote:
> John Peterson wrote:
>> Add a type signature:
>> prime :: Integer -> Bool
>> It's defaulting to Int and you're getting overflows
>
> Thanks. Hmm... it's still not working.
>
> Btw, I mis-reported the problem. The offending number is 38466629,
> which is /not/ prime but the sample program reports as prime.
>
> 38466629 = 31 * 1240859
>
> The offending program is:
> --//--
> prime :: Integer -> Bool
> prime n = not (factors 2 n)
>
> factors :: Integer -> Integer -> Bool
> factors m n | m == n = False
> | m < n = divides m n || factors (m+1) n
>
> divides :: Integer -> Integer -> Bool
> divides a b = (mod a b == 0)
> --//--
>
> The math behind the program seems correct... :(
>
> Cheers,
> Daniel.
>
>
>
> --
> /\/`) http://oooauthors.org
> /\/_/ http://opendocumentfellowship.org
> /\/_/
> \/_/ I am not over-weight, I am under-tall.
> /
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
More information about the Haskell-Cafe
mailing list