Skip to content

Instantly share code, notes, and snippets.

@sanemat
Created March 29, 2012 05:04
Show Gist options
  • Save sanemat/2233519 to your computer and use it in GitHub Desktop.
Save sanemat/2233519 to your computer and use it in GitHub Desktop.
goldbach a = head $
filter (\(x,y) -> isPrime x && isPrime y) $
map (\e -> (e, a - e)) [1,3..a `div` 2]
where
factors a = filter (isFactor a) [2..a-1]
isFactor a b = a `mod` b == 0
isPrime 1 = False
isPrime a = null $ factors a
@sanemat
Copy link
Author

sanemat commented Mar 29, 2012

*Main> goldbach 28
(5,23)
*Main> goldbach 14
(1,13)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment