Guest User

Untitled

a guest
Nov 13th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.45 KB | None | 0 0
  1. let rec arr_exists p arr b e =
  2.    if b >= e
  3.       then false
  4.       else if p arr.(b)
  5.          then true
  6.          else arr_exists p arr (b + 1) e
  7.  
  8. let n_primes n =
  9.    let rec gather c x ps =
  10.       if c == n
  11.          then ps
  12.          else if arr_exists (fun y -> x mod y = 0) ps 0 c
  13.             then gather c (x + 2) ps
  14.             else (ps.(c) <- x; gather (c + 1) (x + 2) ps)
  15.    in gather 1 5 (Array.make n 2) ;;
  16.  
  17. print_int (n_primes 100000).(99999)
Advertisement
Add Comment
Please, Sign In to add comment