text
stringlengths 0
601k
|
---|
let fact (n: int): float = let rec helper n (acc: float): float = if n=0 then acc else helper (n-1) ((float_of_int n) *. acc) in if n < 0 then domain() else helper n 1. ;; |
let binomial (n: int) (k: int) : float = if k > n || n<0 || k<0 then domain () else (fact n) /. ((fact k) *. (fact (n - k))) ;; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = if x1<0 || y1<0 || x2<0 || y2<0 then domain () else let dx = float_of_int (x2 - x1) in let dy = float_of_int (y2 - y1) in sqrt ( (dx *. dx) +. (dy *. dy) ) ;; |
let is_prime (n: int ): bool = if n <= 1 then domain () else let rec helper n i = if n = 2 then true else if n mod i = 0 then false else if (i * i > n) then true else helper n (i+1) in helper n 2 ;; |
let rec fib_aux n a b = if n <= 1 then b else fib_aux (n-1) b (a+b) let fib_tl n = if n<0 then domain () else fib_aux n 1 1 ;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> (float_of_int(n) *. fact (n - 1)) ;; |
let binomial (n: int) (k: int) = fact n /. (fact k *. fact (n - k));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x1 - x2 in let dy = y1 - y2 in sqrt (float_of_int(dx * dx + dy * dy)) ;; |
let is_prime n : bool = let rec counter x : bool = if x * x <= n then if n mod x = 0 then false else counter (x + 1) else true in counter 2;; let pi = 4. *. atan(1.);; |
let rec fib_aux n a b = if n = 0 then a else fib_aux(n-1) (a+b) a ;; let fib_tl n = fib_aux n 1 0 ;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int n *. fact (n - 1) ;; |
let binomial (n: int) (k: int) : float = if n < 0 || k < 0 || k > n then domain () else fact n /. (fact k *. fact (n - k)) ;; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x2 - x1 in let dy = y2 - y1 in sqrt (float_of_int (dx * dx + dy * dy)) ;; |
let is_prime (n: int) : bool = let rec prime_rec_helper (cur: int) (max: int) : bool = if cur > max then true else if n mod cur = 0 then false else prime_rec_helper (cur + 1) max in prime_rec_helper 2 (int_of_float (sqrt (float_of_int n))) ;; |
let rec fib_aux (n: int) (a: int) (b: int) = match n with | 0 -> b | 1 -> a + b | _ -> fib_aux (n-1) b (a+b) ;; let fib_tl (n: int) = if n < 0 then domain () else fib_aux n 0 1 ;; |
let rec fact (n: int): float = if n < 0 then domain() else match n with | 0 -> 1. | _ -> float n *. fact (n - 1);; |
let binomial (n: int) (k: int) = if n < 0 || k < 0 || k > n then domain () else fact n /. (fact k *. fact (n - k));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x1 - x2 in let dy = y1 - y2 in sqrt (float (dx * dx + dy * dy)) ;; |
let is_prime n = if n < 2 then domain() else let rec helper n k = if float k > sqrt (float n) then true else if n mod k = 0 then false else helper n (k + 1) in helper n 2;; |
let rec fib_aux n a b = match n with 0 | 1 -> b | _ -> fib_aux (n - 1) b (a + b) let fib_tl n = if n < 0 then domain() else fib_aux n 1 1;; |
let rec fact (n): float = match n with | 0 -> 1. | 1 -> 1. | _ -> float_of_int n *. (fact (n-1));; |
let binomial (n: int) (k: int) : float = if (n < 0 || n < k) then domain () else (fact(n)) /. ((fact k) *. (fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = (x2 - x1) in let dy = (y2 - y1) in sqrt(float_of_int((dx * dx) + (dy * dy))) ;; |
let is_prime (n: int) : bool = if n < 2 then domain() else ( let i = n - 1 in let rec prime n i : bool = if i <= 1 then true else (if i > 1 && n mod i = 0 then false else prime n (i - 1) ) in prime n i );; |
let rec fib_aux n a b = if (n>1) then fib_aux (n-1) b (a+b) else b let fib_tl n = fib_aux n 1 1;; |
let rec fact (n: int) = match n with | 0 -> 1. | 1 -> 1. | _ -> float_of_int n *. (fact (n-1));; |
let binomial (n: int) (k: int) : float = if (n < 0 || n < k) then domain () else (fact(n)) /. ((fact k) *. (fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = (x2 - x1) in let dy = (y2 - y1) in sqrt(float_of_int((dx * dx) + (dy * dy))) ;; |
let is_prime (n) : bool = if n < 2 then domain() else ( let i = n - 1 in let rec prime n i : bool = if i <= 1 then true else (if i > 1 && n mod i = 0 then false else prime n (i - 1) ) in prime n i );; |
let rec fib_aux n a b = if (n>1) then fib_aux (n-1) b (a+b) else b let fib_tl n = fib_aux n 1 1;; |
let fact (n: int): float = if n < 0 then domain () else let rec fact_help n acc = match n with | 0 -> acc | _ -> fact_help (n-1) (acc *. (float_of_int n)) in fact_help n 1.;; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if n < k then domain () else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x1-x2 in let dy = abs(y1-y2) in sqrt(float(dx * dx + dy * dy)) ;; |
let is_prime n = let rec is_prime_help d = (n mod d != 0 && is_prime_help (d + 1)) || d * d > n in if n <= 1 then domain () else is_prime_help 2;; |
let rec fib_aux n a b = if n = 0 then a else fib_aux (n-1) b (a+b) let fib_tl n = if n < 0 then domain () else fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int(n) *. fact (n - 1);; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n then domain () else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x2 - x1 in let dy = y2 - y1 in sqrt (float_of_int(dx * dx) +. float_of_int(dy * dy)) ;; |
let is_prime (n: int): bool = if n <= 1 then domain() else( let rec prime x = if x * x > n then true else(if n mod x = 0 then false else( prime (x + 1))) in prime 2);; |
let rec fib_aux n a b = match n with | 0 -> a | 1 -> b | _ -> fib_aux (n - 1) b (a + b) let fib_tl n = fib_aux n 1 1 ;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float (n) *. fact (n - 1) ;; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n then domain () else fact (n) /. (fact (k) *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x1 - x2 in let dy = y1 - y2 in sqrt (float (dx * dx + dy * dy)) ;; let rec is_prime2 n i = let max = int_of_float (sqrt (float n)) in if n mod i = 0 then false else (if i > max then true else is_prime2 n (i + 1)) ;; |
let is_prime (n:int) = if n <= 1 then domain () else (n = 2) || (is_prime2 n 2) ;; |
let rec fib_aux n a b = if n <= 0 then b else (if n = 1 then a else fib_aux (n-1) b (a + b)) ;; let fib_tl n = if n < 0 then domain () else ( if n = 0 then 1 else fib_aux n 1 2) ;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int n *. fact (n - 1);; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n || k < 0 then domain () else if k = 0 then 1. else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x2 - x1 in let dy = y2 - y1 in sqrt ((float_of_int dx) *. (float_of_int dx) +. (float_of_int dy) *. (float_of_int dy));; |
let is_prime n = if n <= 1 then domain() else if n = 1 then false else (let rec check n x = if x * x > n then true else if (n / x) * x = n then false else check n (x + 1) in check n 2);; |
let rec fib_aux n a b = if n = 0 then a else if n = 1 then b else fib_aux (n - 1) b (a + b) let fib_tl n = if n < 0 then domain() else fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int n *. fact (n - 1);; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n || k < 0 then domain () else if k = 0 then 1. else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x2 - x1 in let dy = y2 - y1 in sqrt ((float_of_int dx) *. (float_of_int dx) +. (float_of_int dy) *. (float_of_int dy));; |
let is_prime n = if n <= 1 then domain() else if n = 1 then false else (let rec check n x = if x * x > n then true else if (n / x) * x = n then false else check n (x + 1) in check n 2);; |
let rec fib_aux n a b = if n = 0 then a else if n = 1 then b else fib_aux (n - 1) b (a + b) let fib_tl n = if n < 0 then domain() else fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int n *. fact (n - 1);; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n || k < 0 then domain () else if k = 0 then 1. else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x2 - x1 in let dy = y2 - y1 in sqrt ((float_of_int dx) *. (float_of_int dx) +. (float_of_int dy) *. (float_of_int dy));; |
let is_prime n = if n < 1 then domain() else if n = 1 then false else (let rec check n x = if x * x > n then true else if (n / x) * x = n then false else check n (x + 1) in check n 2);; |
let rec fib_aux n a b = if n = 0 then a else if n = 1 then b else fib_aux (n - 1) b (a + b) let fib_tl n = if n < 0 then domain() else fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int(n) *. (fact (n - 1));; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n then domain () else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = abs(x1 - x2) in let dy = abs(y1 - y2) in sqrt (float_of_int(dx * dx + dy * dy)) ;; let rec div (n: int) (i: int) = if (n = i) then true else if (n mod i = 0) then false else div (n) (i+1) ;; |
let is_prime (n: int): bool = match n with | 0 -> domain() | 1 -> domain() | 2 -> true | _ -> let i = 2 in div n i ;; |
let rec fib_aux n a b = if n = 0 then a else fib_aux (n - 1) b (a + b) let fib_tl n = if n < 0 then domain() else if n = 0 then 1 else if n = 1 then 1 else fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int(n) *. (fact (n - 1));; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n then domain () else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = abs(x1 - x2) in let dy = abs(y1 - y2) in sqrt (float_of_int(dx * dx + dy * dy)) ;; let rec div (n: int) (i: int) = if (n = i) then true else if (n mod i = 0) then false else div (n) (i+1) ;; |
let is_prime (n: int): bool = match n with | 0 -> domain() | 1 -> domain() | 2 -> true | _ -> let i = 2 in div n i ;; |
let rec fib_aux n a b = if n = 0 then a else fib_aux (n - 1) b (a + b) let fib_tl n = if n < 0 then domain() else if n = 0 then 1 else if n = 1 then 1 else fib_aux n 1 1;; |
let rec fact (n: int): float = if n=0 then 1.0 else float_of_int(n)*.fact(n-1);; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n then domain () else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x1 - x2 in let dy = y1 - y2 in sqrt(float_of_int(dx * dx + dy * dy)) ;; |
let is_prime n = if n<=1 then domain() else let rec f n x = if (x*x<=n) then if (n mod x = 0) then false else f n (x+1) else true in f n 2 ;; |
let rec fib_aux n a b = if n=1 then b else if (n mod 2 = 0) then fib_aux (n-1) a (a+b) else fib_aux (n-1) (a+b) b ;; let fib_tl n = if n=0 || n=1 then 1 else fib_aux n 1 1 ;; |
let rec fact (n: int): float = match n with | 0 -> 1. | 1 -> 1. | _ -> (fact(n - 1)/.fact(n - 2)+.1.) *. fact(n - 1) ;; |
let binomial (n: int) (k: int): float = if n < 0 then domain () else if k <0 then domain () else fact(n)/. (fact(k) *. fact (n-k)) ;; let rec int2flt (n: int): float = match n with | 0 -> 0. | _ -> int2flt(n - 1)+.1.;; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dissq=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2) in sqrt(int2flt dissq) ;; let rec effective_mod_check (n:int) (m:int):bool= if m==1 then true else let a=n mod m in if a >0 then effective_mod_check n (m-1) else false;; |
let is_prime (n:int): bool= if n<=1 then domain() else if n==2 then true else if n==3 then true else effective_mod_check n (n/2) ;; |
let rec fib_aux (n:int) (a:int) (b:int) = if n=1 then b else if n=0 then a else if n<0 then domain() else fib_aux (n-1) b (a+b) let fib_tl n = fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> (float_of_int n) *. (fact (n - 1));; |
let binomial (n: int) (k: int) : float = if n < 0 || k < 0 then domain () else (if k > n then domain () else (fact n) /. ((fact k) *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = float_of_int (x2 - x1) in let dy = float_of_int (y2 - y1) in sqrt ((dx *. dx) +. (dy *. dy)) ;; |
let is_prime n = let rec factors n x = if x = 1 then 0 else match n mod x with | 0 -> 1 | _ -> factors n (x - 1) in if n < 1 then domain() else if n = 2 then true else (match factors n (n / 2) with | 1 -> false | _ -> true );; |
let rec fib_aux n a b = if n < 0 then domain() else match n with | 0 -> a | 1 -> b | _ -> fib_aux (n - 1) (b + a) b let fib_tl n = fib_aux n (n - 1) (n - 2);; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> (float_of_int n) *. (fact (n - 1));; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x1 - x2 in let dy = y1 - y2 in sqrt ( float_of_int ( dx * dx + dy * dy ) ) ;; |
let is_prime (n: int) = let rec helper n x = if n < 2 then domain () else if x * x > n then true else if (n mod x) = 0 then false else helper n (x + 1) in helper n 2 ;; |
let rec fib_aux n a b = if n > 0 then fib_aux (n-1) b (a + b) else a + b let fib_tl n = if n < 2 then 1 else fib_aux (n - 2) 1 1 ;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> (float_of_int n) *. (fact (n - 1));; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k > n then domain () else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = float_of_int (x1 - x2) in( let dy = float_of_int (y1 - y2) in sqrt (dx *. dx +. dy *. dy)) ;; |
let is_prime n = if n <= 1 then domain() else let rec helper k = if (k*k) > n then true else if (n mod k) != 0 then helper (k+1) else false in helper 2;; |
let rec fib_aux n a b = if n = 0 then a else fib_aux (n-1) b (a+b) let fib_tl n = if n < 0 then domain() else fib_aux n 1 1;; |
let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float_of_int n *. fact (n - 1);; |
let binomial (n: int) (k: int) = if n < 0 then domain () else (if k = n then 1. else fact n /. (fact k *. fact (n - k)));; |
let distance ((x1, y1): (int * int)) ((x2, y2): (int * int)) : float = let dx = x2 - x1 in let dy = y2 - y1 in sqrt (float_of_int(dx * dx + dy * dy)) ;; |
let is_prime n = if n <=1 then domain() else let rec divides x = x * x <= n && (n mod x = 0 || divides (x + 1)) in not(divides 2);; |
let rec fib_aux n a b = if n = 0 then a else fib_aux (n - 1) b (a + b) let fib_tl n = if n = 0 then 1 else fib_aux n 1 1;; |