
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. /

Daniel,
Could it be that the arguments to either divides or mod should be reversed?
Currently it seems to be testing whether the candidate prime (n)
divides the possible factor (m).
Or am I to tired to read the code straight?
Regards,
Maarten
On 12/20/05, Daniel Carrera
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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi Daniel! You just have to change the arguments of the 'mod'-function: old: divides a b = (mod a b == 0) new: divides a b = (mod b a == 0) Regards, Jens

-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@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Robert Dockins wrote:
-divides a b = (mod a b == 0) +divides a b = (mod b a == 0)
Oh, thanks. My program assumed one way to define 'divides' and the example assumed the other. When I wrote it I was thinking of (divides a) being a function that tells me if the input divides 'a'. Thanks! Cheers, Daniel. -- /\/`) http://oooauthors.org /\/_/ http://opendocumentfellowship.org /\/_/ \/_/ I am not over-weight, I am under-tall. /
participants (4)
-
Daniel Carrera
-
Jens Fisseler
-
Maarten Hazewinkel
-
Robert Dockins