F# has 'easy button' for finding large primes! 29
lines of code! Thanks to Chris
Smith and his 'completely unique view' on the Sieve of Eratosthenes
#light
open System.Collections.Generic
open System
let findPrimes =
seq {
yield 2 //2 is a known prime
let knownComposites = new HashSet<int>()
//Visit each odd
for i in 3 .. 2 .. int 1E6 do
// Check known composites, if not present, it is prime.
let found = knownComposites.Contains(i)
if not found then
yield i
// Add all multiples of i to our sieve, starting
// at i and irecementing by i.
do for j in i .. i .. int 1E6 do
knownComposites.Add(j) |> ignore
}
printfn "Here are the first 10001 primes:"
Seq.iter (fun p -> printf "\t%d" p) (Seq.take 10001 findPrimes)
Console.ReadKey(true)