Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

haskell assignment

Name: Anonymous 2007-02-15 8:45

I need to write a Haskell function that takes in k where k is an even number >2, and returns x and y such that k = x + y, and x and y are primes (Goldbach's conjecture).

I've really been struggling @ understanding Haskell, and I don't think I'll be able to solve it in... 12 hours.  Halp please....  Anyone...

;_;

Name: Anonymous 2007-02-15 19:52

OP here
>>7
Thanks!  Finally got it working.
I ganked a primes module online that generates an infinite list of primes, but couldn't get it to run w/ my goldbach function.  The problem was that I was trying to do:

head [ (x, y) | isPrime x, isPrime y, x + y == k ]

Which gives me an error stating x and y are not in scope.  I didn't understand it, so I tried your way, doing x <- primes, etc.  But it hangs producing infinite lists of primes.  Then I realized that I have to do the <- thing.  So I basically just had to add x <- [1..k] and made y = k - x, so now it gives a complete list of pairs and is fast even for really large numbers.


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List