Skip to content

Instantly share code, notes, and snippets.

@ecounysis
Last active August 29, 2015 14:09
Show Gist options
  • Save ecounysis/78ad1f7adb5f6d863e93 to your computer and use it in GitHub Desktop.
Save ecounysis/78ad1f7adb5f6d863e93 to your computer and use it in GitHub Desktop.
primes
let divisors x =
List.init (int (Math.Sqrt(float x))) (fun x -> x + 1)
|> List.filter (fun y -> x % y = 0)
|> List.map (fun y -> [y ; x / y])
|> List.reduce (fun x y -> x @ y)
|> List.sort
let isPrime x =
List.length (divisors x) = 2
let primesBetween x y =
seq { for num in x..y do
if (isPrime num)
then yield num }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment