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

Pages: 1-

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 9:10

the equation is already at wikipedia
just convert the equation

http://en.wikipedia.org/wiki/Goldbach%27s_conjecture

Name: Anonymous 2007-02-15 12:43

>>1
It's NP-complete, just give it up.

Name: Anonymous 2007-02-15 13:06

>>3
uh.. you can implement NP complete algorithms they are just slow.

Name: Anonymous 2007-02-15 15:05

>>4
I AM LINUX TARBALLS.  FOUNDER AND CEO OF NP-COMPLETE PROBLEMS.  I GAVE IT UP A LONG TIME AGO AND EMBRACED A YOUNG MALE DRESSED IN A DAPPER DRAKESUIT.  I GUARANTEE IT.

Name: Anonymous 2007-02-15 16:35

OP here
>>2
Sorry, I meant that I do not know how to implement it in Haskell.  If it was, lets say, C++, I can implement it just fine.

Name: Anonymous 2007-02-15 18:54

Here's how not to do it:

primes = [1,2,3,5,7,11]

shit k | even k, k > 2 =
    head [ (x,y) | x <- primes, y <- primes, x + y == k ]

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.

Name: Anonymous 2007-02-15 19:54

>>8
gj! omedetou!

Name: Anonymous 2007-02-16 5:06 (sage)

>>9
^_^

Name: Anonymous 2007-02-16 16:35 (sage)

>>9
I lol'd.

Name: Anonymous 2010-06-25 14:49

WARNING: NECRO POST

Name: Anonymous 2011-02-04 17:56

Name: Sgt.Kabu犒妔kiman阉ꩨ 2012-05-28 22:32

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

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