Advertisement
bergius

Prime sequence

May 4th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.38 KB | None | 0 0
  1. let isPrime = function
  2.     | 0L | 1L -> false
  3.     | n ->
  4.         let h = n / 2L
  5.         let rec f = function
  6.             | x when x > h -> true
  7.             | x when n % x = 0L -> false
  8.             | x -> f (x + 1L)
  9.         f 2L
  10.  
  11. let primes =
  12.     let rec primes n = seq {
  13.         if isPrime n then
  14.             yield n
  15.         yield! primes (n + 1L)
  16.     }
  17.     primes 2L
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement