Skip to content

Instantly share code, notes, and snippets.

@vishakvkt
Last active December 29, 2015 02:09
Show Gist options
  • Save vishakvkt/7598819 to your computer and use it in GitHub Desktop.
Save vishakvkt/7598819 to your computer and use it in GitHub Desktop.
let is_prime n =
match n with
|n when n < 2 -> false
|n when n = 2 || n = 3 -> true
|n when n % 2 = 0 || n % 3 = 0 -> false
|n ->
let rec check i rootn n =
if i > rootn then true
else
if n % i = 0 then false
else check (i+1) rootn n
check 5 (int (sqrt (float n))) n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment