Skip to content

Instantly share code, notes, and snippets.

@rodrigovidal
Created October 19, 2011 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigovidal/1297629 to your computer and use it in GitHub Desktop.
Save rodrigovidal/1297629 to your computer and use it in GitHub Desktop.
Crivo de Eratostenes beeem melhor em F#
let sieveOfEratosthenes n =
let arr = [| for i in 0..n -> 1 |]
let sqrt = sqrt(float n) |> int
for k = 2 to sqrt + 1 do
if arr.[k] = 1 then
for j in 2*k..k..n-1 do
arr.[j] <- 0
seq { for i in 2..n-1 do if arr.[i] = 1 then yield i }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment