Created
August 19, 2011 15:50
-
-
Save davidgrenier/1157134 to your computer and use it in GitHub Desktop.
Project Euler 7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec primes = | |
let isPrime n = | |
primes | |
|> Seq.takeWhile (fun v -> v <= (float n |> sqrt |> int64)) | |
|> (not << Seq.exists (fun v -> n % v = 0L)) | |
let rec primes' n = seq { | |
if isPrime n then | |
yield n | |
yield! primes' (n + 2L) | |
} | |
seq { | |
yield 2L | |
yield! primes' 3L | |
} |> Seq.cache;; | |
primes |> Seq.nth 10000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment