Skip to content

Instantly share code, notes, and snippets.

@dungpa
Created March 10, 2012 10:07
Show Gist options
  • Save dungpa/2011023 to your computer and use it in GitHub Desktop.
Save dungpa/2011023 to your computer and use it in GitHub Desktop.
Find a few first Mersenne numbers
let inline mersenne (i: int) =
if i = 2 || (isPrime (bigint i) && lucasLehmer i) then
let p = 1I <<< i
Some (i, (p/2I) * (p-1I))
else None
let runPerfectsSeq n =
seq {1..n}
|> Seq.choose mersenne
|> Seq.toArray
let runPerfectsPSeq n =
seq {1..n}
|> PSeq.choose mersenne
|> PSeq.sort
|> PSeq.toArray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment