Skip to content

Instantly share code, notes, and snippets.

@vishakvkt
Last active December 25, 2015 02:29
Show Gist options
  • Save vishakvkt/6903257 to your computer and use it in GitHub Desktop.
Save vishakvkt/6903257 to your computer and use it in GitHub Desktop.
let sieve upperbound =
let ar = Array.create (upperbound+1) 1
for i in 2.. (ar.Length - 1) do
let endi = int (floor (float (upperbound/i)))
for j in i..endi do
ar.[i * j] <- 0
seq{for i in 2..(ar.Length - 1) do if ar.[i] = 1 then yield i}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment