text
stringlengths
0
601k
let pascal (max : int) : int list list = if max = 0 then [] else let is_done = fun (l: int list) -> ((List.length l) > max) || (List.length l = 1 && max = 1) in unfold next_pascal is_done [] ;; let next_zip ((a, b) : 'a list * 'b list) : ('a * 'b) * ('a list * 'b list) = ((List.hd a, List.hd b), (List.tl a, List.tl b)) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let equals_ingred = fun b a -> a = b in let in_allergen = fun (a: ingredient) -> not (List.exists (equals_ingred a) allergens) in let contain_allergen = fun (c : cupcake) -> (let Cupcake(a, b, d, i) = c in List.for_all in_allergen i) in List.filter contain_allergen cupcakes ;;
let string_explode (s : string) : char list = tabulate (fun n -> String.get s n) (String.length s);;
let string_implode (l : char list) : string = let append s c = s ^ Char.escaped c in List.fold_left (append) "" l;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a, b) -> (a, (b, a+b))) (fun (a, b) -> a >= max) (1, 1) let rec fact (n: int): int = if n < 0 then domain() else match n with | 0 -> 1 | _ -> 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 pascal (max : int) : int list list = let rec row n k r = if (k > n) then r else (row n (k+1) (List.append r [binomial n k])) in unfold (fun b -> ((row b 0 []), b+1)) (fun b -> b >= max) 0;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_, _, _, ingredients) -> not (List.exists (function x -> contains x allergens) ingredients)) cupcakes;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = let stringlist = List.map (Char.escaped) l in List.fold_left (^) "" stringlist ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b-> max <= b) 0 ;;
let fib (max : int) : int list = let tuplelist = unfold (fun (a,b) -> ((a,b), (b, b+a))) (fun (a,b) -> max <= b) (0,1) in List.map snd tuplelist ;;
let pascal (max : int) : int list list = unfold (fun b -> (b, List.map2 (+) (List.append [0] b) (List.append b [0]))) (fun b -> max < List.length b) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( fun cake -> let Cupcake (a,b,c,ingredients) = cake in not ( List.exists ( fun allergen -> List.exists ( fun ingredient -> ingredient = allergen ) ingredients ) allergens ) ) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = let stringlist = List.map (Char.escaped) l in List.fold_left (^) "" stringlist ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b-> max <= b) 0 ;;
let fib (max : int) : int list = let tuplelist = unfold (fun (a,b) -> ((a,b), (b, b+a))) (fun (a,b) -> max <= b) (0,1) in List.map snd tuplelist ;;
let pascal (max : int) : int list list = unfold (fun b -> (b, List.map2 (+) (List.append [0] b) (List.append b [0]))) (fun b -> max < List.length b) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( fun cake -> let Cupcake (a,b,c,ingredients) = cake in ( List.for_all ( fun ingredient -> not (List.exists ( fun allergen -> ingredient = allergen ) allergens ) ) ingredients ) ) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = let l1 = List.map Char.escaped l in String.concat "" l1;;
let evens (max : int) : int list = let nats max = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0 in nats max;;
let fib (max : int) : int list = match max with | 0 -> [] | 1 -> [] | 2 -> [1;1] | _ -> let l1 = [1;1] in let nats max = unfold (fun (a,b) -> (a+b, (b, a+b))) (fun (a,b) -> max <= a+b) (1,1) in let r = List.append l1 (nats max) in r;;
let pascal (max : int) : int list list = unfold (fun b -> (b, List.map2 (+) (List.append [0] b) (List.append b [0]))) (fun b -> max < List.length b) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if (List.for_all ( fun c -> let Cupcake (_,_,_,ingredients) = c in (List.for_all (fun allergen -> List.for_all (fun ingredient -> ingredient != allergen) ingredients) allergens) ) cupcakes) then cupcakes else List.filter ( fun c -> let Cupcake (_,_,_,ingredients) = c in not (List.exists (fun allergen -> List.exists (fun ingredient -> ingredient = allergen) ingredients) allergens) ) cupcakes ;;
let string_explode (s : string) : char list = tabulate (fun x -> String.get s x) (String.length s) ;;
let string_implode (l : char list) : string = String.concat "" (List.map (String.make 1) l) ;;
let evens (max : int) : int list = unfold ( fun b -> ( b, b + 2 )) ( fun b -> max <= b ) 0 ;;
let fib (max : int) : int list = unfold ( fun (b1,b2) -> ( b1, (b2, b1 + b2))) ( fun (b1,b2) -> max <= b1 ) (1,1) ;;
let pascal (max : int) : int list list = unfold(fun (n,i) -> ( n, (List.map2 (+) (0 :: n) (n @ [0] ),i+1) )) ( fun (n,i) -> max <= List.length n - 1) ([1],0) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let allergens_exist noallin = not (let exist aller = (aller = noallin) in List.exists exist allergens) in let check_allergens cakes = let Cupcake( _, _, _, ingredients) = cakes in List.for_all allergens_exist ingredients in List.filter check_allergens cupcakes ;;
let string_explode (s : string) : char list = let make = String.get s in tabulate make (String.length s) ;; let rec turn i (l: char list) lc = if i<0 then lc else turn (i-1) l ((Char.escaped (List.nth l i)) :: lc) ;;
let string_implode (l : char list) : string = List.fold_left (^) "" (turn (List.length l - 1) l []) ;;
let evens (max : int) : int list = unfold (fun b -> b, b + 2) (fun x -> x >= max) 0 ;;
let fib (max : int) : int list = let check (l: int list) = match l with | [] -> false | h::_ -> h >= max in unfold (fun [h;t] -> h,[t;h+t]) check [1;1] ;; let row l1 = let l2 = [0]@l1@[0] in let rec add l = match l with |[] -> [] |h::t -> match t with |[] -> [] |s::t' -> (h+s)::add(s::t') in l1, (add l2) ;;
let pascal (max : int) : int list list = unfold row (fun l -> List.length l > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec checkList l = match l with | [] -> true | h::t -> if(List.exists (checkHead h) allergens) then false else checkList t in let findOne (c:cupcake) = let Cupcake (_,_,_,l) = c in checkList l in let cupL = (List.filter findOne cupcakes) in if List.for_all findOne cupL then cupL else [] ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = List.fold_left (^) "" (List.map Char.escaped l);;
let evens (max : int) : int list = if max = 0 then [] else unfold (fun b -> (b, b+2)) (fun b -> (max <= b) ) 0 ;;
let fib (max : int) : int list = unfold (fun (a,b) -> (a , (b, a + b))) (fun (a,b) -> max <= a) (1,1) ;;
let pascal (max : int) : int list list = if max = 0 then [] else List.append [[1]] (unfold (fun (1::xs) -> ((1::xs), (List.append [1] (List.map2 (+) (List.append [1] xs) (List.append xs [0]))))) (fun ls -> max < List.length ls) [1;1]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,ingre) -> (List.for_all (fun i -> (not(List.exists ((=) i) ingre))) allergens)) cupcakes ;;
let string_explode (s : string) : char list = let extract = fun n -> String.get s n in tabulate extract (String.length s);;
let string_implode (l : char list) : string = List.fold_right (fun x y -> (Char.escaped x) ^ y) l "";;
let evens (max : int) : int list = let nats max = unfold (fun b -> (b, b+1)) (fun b -> max <= b) 0 in List.filter (fun x -> x mod 2 = 0) (nats max);;
let fib (max : int) : int list = let fibs maximum = unfold (fun b -> (snd(b),(snd(b),snd(b)+fst(b)))) (fun b -> maximum <= snd(b)) (0,1) in fibs max ;;
let pascal (max : int) : int list list = let pasc maximum = unfold (fun b -> (b, (List.map2 (+) b (List.rev (List.tl (List.rev b) @ [0]))) @ [1])) (fun b -> maximum < (List.length b)) [1] in pasc max ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) let char_to_string = String.make 1;;
let string_implode (l : char list) : string = List.fold_left (fun a b -> a ^ (char_to_string b)) "" l;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> b >= max) 0;;
let fib (max : int) : int list = unfold (fun b -> (snd b, (snd b, fst b + snd b))) (fun b -> snd b >= max) (0, 1) let binomInt (nI : int) (pI : int) : int= let binomFloat n p = let p = if p < n -. p then p else n -. p in let rec cm res num denum = if denum <= p then cm ((res *. num) /. denum) (num -. 1.) (denum +. 1.) else res in cm 1. n 1. in binomFloat (float_of_int nI) (float_of_int pI) |> int_of_float;;
let pascal (max : int) : int list list = let genPascalRow rn = unfold (fun k -> (binomInt rn k, k+1)) (fun k -> k > rn) 0 in unfold (fun rn -> (genPascalRow rn, rn+1)) (fun rn -> rn >= max) 0;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (_, _, _, il)) -> List.for_all (fun a -> not (List.exists (fun e -> e=a) il)) allergens) cupcakes;;
let string_explode (s : string) : char list = let n = String.length s in let f = String.get s in tabulate f n;;
let string_implode (l : char list) : string = let ls = List.map Char.escaped l in List.fold_left (^) "" ls;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0;;
let fib (max : int) : int list = let f (a, b) = (b, (b, a+b)) in unfold f (fun (a,b) -> max <= b) (0, 1);;
let pascal (max : int) : int list list = let next_row l = let l1 = List.append l [0] in let l2 = List.append [0] l in List.map2 (+) l1 l2 in unfold (fun (l) -> (l, next_row l)) (fun l -> max < List.length l) ([1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let res = cupcakes in let a = List.for_all (fun x -> x=Dairy) allergens in let check_dairy c : bool = let Cupcake(_,_,_, ingredients) = c in not (List.exists (fun x -> x=Dairy) ingredients) in let check_gluten c : bool = let Cupcake(_,_,_, ingredients) = c in not (List.exists (fun x -> x=Gluten) ingredients) in let check_soy c : bool = let Cupcake(_,_,_, ingredients) = c in not (List.exists (fun x -> x=Soy) ingredients) in let check_nuts c : bool = let Cupcake(_,_,_, ingredients) = c in not (List.exists (fun x -> x=Nuts) ingredients) in if allergens = [] then cupcakes else let res = List.filter check_nuts res in let res = List.filter check_gluten res in let res = List.filter check_soy res in List.filter check_dairy res;;
let string_explode (s : string) : char list = tabulate (String.get(s)) (String.length(s));;
let string_implode (l : char list) : string = List.fold_left(^) ("") (List.map (Char.escaped) l);;
let evens (max : int) : int list = unfold (fun x -> (x, x+2))((<=) max)(0);;
let fib (max : int) : int list = unfold (fun (x,y)-> (x, (y,x+y)))(fun (x,y) -> max <= x)(1,1);;
let pascal (max : int) : int list list = raise NotImplemented;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter(function Cupcake (_,_,_,ingredients) -> List.for_all(fun ingredient -> not (List.exists (fun allergen -> allergen == ingredient) allergens)) ingredients) cupcakes;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = let string_list = List.map Char.escaped l in String.concat "" string_list ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a, b) -> (a, (b, a + b))) (fun (a, b) -> a >= max) (1, 1);;
let pascal (max : int) : int list list = unfold (fun b -> (b, [List.hd b]@List.map2 (+) (List.rev ((List.tl (List.rev b)))) ((List.tl (List.rev b)))@[List.hd b])) (fun b -> List.length b > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,ingredients) -> List.for_all (fun ingred -> not (List.exists ((=) ingred) ingredients)) allergens) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = List.fold_right (fun c -> (^) (Char.escaped c)) l "";;
let evens (max : int) : int list = unfold (fun b -> (b,b+2)) (fun b -> max <= b ) 0;;
let fib (max : int) : int list = unfold (fun (a,b) -> (a, (b,a+b))) (fun (a,b) -> max <= a) (1,1);;
let pascal (max : int) : int list list = unfold (fun (l, row) -> (l,((1 :: List.map2 (+) (List.tl l) (List.rev (List.tl (List.rev l))) @ [1]),row+1))) (fun (l, row) -> max < row ) ([1],1);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun cake -> let Cupcake (_,_,_,inglist) = cake in List.for_all (fun i -> not (List.exists (fun input_i -> i = input_i) allergens)) inglist) cupcakes;;
let string_explode (s : string) : char list = List.map (String.get s) (tabulate (fun x ->x) (String.length s));;
let string_implode (l : char list) : string = List.fold_left (^) ""( List.map (Char.escaped) l );;
let evens (max : int) : int list = unfold (fun x -> (2 * x , x + 1)) (fun x -> max <= 2*x) 0;;
let fib (max : int) : int list = unfold (fun (x, y) -> (x, (y, x+y))) (fun (x, y) -> x >= max) (1, 1);;
let pascal (max : int) : int list list = unfold (fun cur -> ( cur , (List.map2 (+) (0 :: cur) ( List.append cur [0]) ))) (fun l -> List.length l > max ) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( function Cupcake (_,_,_, l) -> List.for_all ( fun al -> not (List.exists (fun x -> x = al) allergens)) l) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = String.concat "" (List.map Char.escaped l) ;;
let evens (max : int) : int list = unfold (fun b -> (2 * b , b + 1)) (fun b -> (b * 2) >= max) 0 ;;
let fib (max : int) : int list = unfold (fun (n0, n1) -> (n0 + n1, (n1, n0 + n1))) (fun (n0,n1) -> (n0 + n1) >= max) (1,0) ;;
let pascal (max : int) : int list list = raise NotImplemented;;
let pascal (max : int) : int list list = unfold (fun (num, row) -> (row, (num + 1, List.map2 (+) (List.append [0] row) (List.append row [0])))) (fun (num, row) -> num >= max) (0, [1]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun x -> List.for_all ((!=) x) (List.filter (function Cupcake(_,_,_,ingredients_list) -> List.exists (fun x -> List.exists ((=) x) ingredients_list) allergens) cupcakes)) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = String.concat "" (List.map Char.escaped l) ;;
let evens (max : int) : int list = unfold (fun b -> (2 * b , b + 1)) (fun b -> (b * 2) >= max) 0 ;;
let fib (max : int) : int list = unfold (fun (n0, n1) -> (n0 + n1, (n1, n0 + n1))) (fun (n0,n1) -> (n0 + n1) >= max) (1,0) ;;
let pascal (max : int) : int list list = unfold (fun (num, row) -> (row, (num + 1, List.map2 (+) (List.append [0] row) (List.append row [0])))) (fun (num, row) -> num >= max) (0, [1]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun x -> List.for_all ((!=) x) (List.filter (function Cupcake(_,_,_,ingredients_list) -> List.exists (fun x -> List.exists ((=) x) ingredients_list) allergens) cupcakes)) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;