text
stringlengths
0
601k
let string_explode (s : string) : char list = tabulate (fun (idx : int) -> s.[idx]) (String.length s) ;;
let string_implode (l : char list) : string = let str_lst = List.map (Char.escaped) l in List.fold_left (^) "" str_lst ;;
let evens (max : int) : int list = unfold (fun x -> (x, x+2)) ((<=) max) 0 ;;
let fib (max : int) : int list = unfold (fun (x1,x2) -> (x1, (x2, x1+x2))) (fun (x1,x2) -> max <= x1) (1,1) ;;
let pascal (max : int) : int list list = let make_row (old_row : int list) : (int list * int list) = (old_row, List.map2 (+) (0::old_row) (List.append old_row [0])) in unfold (make_row) (fun row -> max < List.length row) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let found_in_list (to_find : ingredient) (ing_lst : ingredient list) : bool = List.exists (fun ing -> ing = to_find) ing_lst in let is_allergen_free (Cupcake (_,_,_,ing_lst)) : bool = List.for_all (fun algn -> not (found_in_list algn ing_lst)) allergens in List.filter (is_allergen_free) cupcakes ;;
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 b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = let next_fib (prev, curr) = (curr, (curr, prev + curr)) in let stop max (_, curr) = (max <= curr) in unfold next_fib (stop max) (0,1);;
let pascal (max : int) : int list list = let next_row row = (row, List.map2 (+) (0 :: row) (row @ [0])) in let stop max row = (max < List.length row) in unfold next_row (stop max) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_allergy_free allergens cupcake = let nexists_eq l x = not (List.exists ((=) x) l) in let Cupcake (_, _, _, ingredients) = cupcake in List.for_all (nexists_eq ingredients) allergens in List.filter (is_allergy_free allergens) cupcakes;;
let string_explode (s : string) : char list = let length = String.length s in let get_char = function n -> String.get s n in let y = function s -> tabulate get_char length in y s;;
let string_implode (l : char list) : string = let make_string = function a_list -> String.concat "" a_list in let x = function list1 -> function character -> List.append list1 [Char.escaped(character)] in make_string (List.fold_left x [] l);;
let evens (max : int) : int list = let f = function seed -> (seed, (seed + 2)) in let stop = function n -> not(n < max) in unfold f stop 0;;
let fib (max : int) : int list = let f = function seed -> List.nth seed 0 + List.nth seed 1, [List.nth seed 1; List.nth seed 0 + List.nth seed 1] in let stop = function n -> not ((List.nth n 0 + List.nth n 1) < max) in unfold f stop [1;0];;
let pascal (max : int) : int list list = let f: int list -> int list * int list = function (seed: int list) -> if seed = [] then [1],[1] else List.map2 (+) (seed@[0]) ([0]@seed), List.map2 (+) (seed@[0]) ([0]@seed) in let stop = function (n: int list) -> not (List.length (List.map2 (+) (n@[0]) ([0]@n)) <= max) in unfold f stop [];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let not_conatins_allergen = function (cake: cupcake) -> function (allergen: ingredient) -> let Cupcake(_,_,_,allergen_list) = cake in not(List.exists (function x -> x = allergen) allergen_list) in let not_contains_any_allergen = function (cake: cupcake) -> List.for_all (not_conatins_allergen cake) allergens in List.filter (not_contains_any_allergen) cupcakes ;;
let string_explode (s : string) : char list = let rec helper i l = if i < 0 then l else helper (i - 1) (s.[i] :: l) in helper(String.length s - 1) [] ;;
let string_implode (l : char list) : string = let helper1 = String.create (List.length l) in let rec helper2 i = function | [] -> helper1 | c :: l -> helper1.[i] <- c; helper2 (i + 1) l in helper2 0 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) -> a >= max) (1, 1);;
let pascal (max : int) : int list list = raise NotImplemented;;
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 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)) ((<=) max) 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 b -> (b, (List.map2 (+) (0 :: b) (b @ [0])))) (fun b -> max <= (List.length b -1)) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter(fun (Cupcake(_,_,_,ingredients)) -> (List.for_all (fun check_ing -> not(List.exists ((=) check_ing) allergens)) ingredients)) 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 n s -> Char.escaped n ^ s) l "";;
let evens (max : int) : int list = unfold (fun n -> (n, n+2)) (fun n -> max <= n) 0;;
let fib (max : int) : int list = unfold (fun (n, m) -> (n, (m, n+m))) (fun (n, m) -> max <= n) (1, 1);;
let pascal (max : int) : int list list = unfold (fun l -> (l, 1 :: (List.map2 (fun m n -> m + n) l (List.tl l @ [0])))) (fun l -> max < List.length l) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (price, weight, calories, ingredients)) -> List.for_all (fun i -> not (List.exists (fun a -> a = i) 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 strlist = List.map Char.escaped l in List.fold_left (^) "" strlist ;;
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) -> (b, (b, a+b))) (fun (a, b) -> max <= b) (0, 1);;
let pascal (max : int) : int list list = unfold (fun b -> (b, (List.map2 (+) ([0] @ b) (b @ [0])))) (fun b -> (max+1) <= List.length b) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let aux_noprob (ingredient : ingredient) (allergens : ingredient list) = (not(List.exists (fun allergen -> (compare allergen ingredient) = 0) allergens)) in let noprob (allergens : ingredient list) (cake : cupcake) = let check_ingredients = ingredients (cake) in if (List.length check_ingredients = 0) then true else if (List.length allergens = 0) then true else (List.for_all (fun ingredient -> (aux_noprob ingredient allergens)) check_ingredients) in List.filter (fun cake -> (noprob allergens cake)) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = List.fold_left (fun x y -> x^(Char.escaped y)) "" 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) -> (b, (b, a+b))) (fun (a,b) -> max <= b) (0,1) ;;
let pascal (max : int) : int list list = unfold (fun l1 -> (l1, (List.map2 (+) (0::l1) (l1@0::[])))) (fun l1 -> max < List.length l1) (1::[]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter(fun x-> (List.for_all(fun y-> not(List.exists((=) y) allergens) ) (c2ilist x)) ) cupcakes;;
let string_explode (s : string) : char list = if String.length s =0 then [] else tabulate (fun x ->String.get s x) (String.length s) ;;
let string_implode (l : char list) : string = match l with |[]->"" |_->List.fold_left (fun s h -> s^Char.escaped(h)) "" l ;;
let evens (max : int) : int list = unfold (fun x -> ((x), (x+2))) (fun x->(x)>=max) 0;;
let fib (max : int) : int list = unfold (fun x -> if (snd x) =0 then (1,(0,1)) else ((fst x)+(snd x)), ((snd x),((fst x)+(snd x)))) (fun x->if max=1 then true else ((fst x)+(snd x))>=max) (0,0);;
let pas (x: int list): int list = List.append (List.append [1] (List.map2 (+) (List.rev(List.tl (List.rev x))) (List.tl x))) [1];;
let pascal (max : int) : int list list = unfold (fun x -> (x, (pas x))) (fun x->List.length(x)>max) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if List.length allergens =0 then cupcakes else List.filter (function Cupcake (_,_,_,ingred_lst) -> ((List.for_all (fun ingred1 -> not (List.exists (fun x -> x = ingred1) ingred_lst))) allergens)) cupcakes;;
let string_explode (s : string) : char list = let get_char = String.get s in tabulate get_char (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 = let fib' ((seed1, seed2) : (int * int)) : (int * (int * int)) = (seed1+seed2, (seed2,seed1+seed2)) in unfold (fib') (fun (seed1,seed2) -> max <= seed1+seed2) (1,0);;
let pascal (max : int) : int list list = let pascal' (pre_row : int list) : (int list * int list) = match pre_row with | [] -> ([1], [1]) | h :: tl -> let seed = List.map2 (+) (List.append [0] pre_row) (List.append pre_row [0]) in (seed, seed) in unfold (pascal') (fun (pre_row) -> max <= (List.length pre_row)) [];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let safe_to_eat (one_cupcake : cupcake) : bool = let in_list (one_ingredient : ingredient) : bool = let check (one_allergen : ingredient) : bool = one_allergen <> one_ingredient in not (List.for_all check allergens) in not (List.exists in_list (get_ingredient_list one_cupcake)) in List.filter safe_to_eat cupcakes;;
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 b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a,b) -> (b, (b,a+b))) (fun (a,b) -> max <= b) (0,1);;
let pascal (max : int) : int list list = unfold (fun a -> (a, (List.map2 (+) (0::a) (List.rev (0::a))))) (fun a -> max + 1 <= (List.length a)) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,r) -> List.for_all (fun x -> not (List.exists ((=) x) allergens)) r) cupcakes;;
let string_explode (s : string) : char list = let rec explode counter acc = if counter < 0 then acc else explode (counter - 1) (String.get s counter :: acc) in explode (String.length s - 1) [];;
let string_implode (l : char list) : string = raise NotImplemented;;
let evens (max : int) : int list = raise NotImplemented;;
let fib (max : int) : int list = raise NotImplemented;;
let pascal (max : int) : int list list = raise NotImplemented;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;;
let string_explode (s : string) : char list = let get_char = String.get s in ( tabulate get_char (String.length s) ) ;;
let string_implode (l : char list) : string = let strings = List.map Char.escaped l in ( String.concat "" strings ) ;;
let evens (max : int) : int list = let f seed = (seed * 2, seed + 1) in let stop seed = (seed * 2 >= max) in unfold f stop 0 ;;
let fib (max : int) : int list = let f (f2, f1) = (f1, (f1, f2 + f1)) in let stop (f2, f1) = (f1 >= max) in unfold f stop (0, 1) ;;
let pascal (max : int) : int list list = let nextlist lst = let lst1 = lst@[0] in let lst2 = 0 :: lst in List.map2 (+) lst1 lst2 in let f (count, lst) = (lst, (count + 1, (nextlist lst))) in let stop (count, lst) = count >= max in unfold f stop (0, [1]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let all_allergen allergens ingredient = List.for_all (not_has allergen ingredient) allergens in let all_cupcakes allergens ing = List.for_all (all_allergen allergens ingredient) ing in let check_ingredient cupcakes = match cupcakes with | Cupcake (_, _, _, list) -> list | _ -> [] in List.filter (all_cupcakes allergens (check_ingredient cupcakes)) cupcakes *) List.filter (fun (Cupcake (_, _, _, lst)) -> (List.for_all (fun ingredient -> (not (List.exists (fun allergen -> (allergen = ingredient)) allergens))) lst)) cupcakes;;
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 failwith "Invalid Input" else unfold (fun n -> (2 * n, n + 1)) (fun m -> 2 * m >= max) 0 ;;
let fib (max : int) : int list = if max < 0 then failwith "Invalid Input" else unfold (fun n -> let (val_1, val_2) = n in val_2, (val_2, val_1 + val_2)) (fun m -> let (val_1, val_2) = m in val_2 >= max) (0,1) ;;
let pascal (max : int) : int list list = if max < 0 then failwith "Invalid Input" else unfold (fun n -> let (l, length) = n in l, (List.map2 (+) (0 :: l) (List.rev (0 :: l)), length + 1)) (fun m -> let (l, length) = m in length > max) ([1], 1) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let cupcake_ingredient_risk (i_cupcake : ingredient) : bool = not (List.exists (function i_allergen -> i_allergen = i_cupcake) allergens) in let risky_cupcake (c : cupcake) : bool = let (Cupcake (price, weight, calories, ingredient_list)) = c in List.for_all (cupcake_ingredient_risk) ingredient_list in List.filter (risky_cupcake) cupcakes ;;
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 failwith "Invalid Input" else unfold (fun n -> (2 * n, n + 1)) (fun m -> 2 * m >= max) 0 ;;
let fib (max : int) : int list = if max < 0 then failwith "Invalid Input" else unfold (fun n -> let (val_1, val_2) = n in val_2, (val_2, val_1 + val_2)) (fun m -> let (val_1, val_2) = m in val_2 >= max) (0,1) ;;
let pascal (max : int) : int list list = if max < 0 then failwith "Invalid Input" else unfold (fun n -> let (l, length) = n in l, (List.map2 (+) (0 :: l) (List.rev (0 :: l)), length + 1)) (fun m -> let (l, length) = m in length > max) ([1], 1) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let cupcake_ingredient_risk (i_cupcake : ingredient) : bool = not (List.exists (function i_allergen -> i_allergen = i_cupcake) allergens) in let risky_cupcake (c : cupcake) : bool = let (Cupcake (price, weight, calories, ingredient_list)) = c in List.for_all (cupcake_ingredient_risk) ingredient_list in List.filter (risky_cupcake) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;; let concat_string s1 s2 : string = String.concat s2 [s1; ""] ;;
let string_implode (l : char list) : string = let l = List.map Char.escaped l in List.fold_left concat_string "" 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 (a, b) -> (a, (b, a + b))) (fun (a, b) -> a >= max) (1, 1) ;; let removefirst = List.tl ;; let rec removelast l = match l with | [x] -> [] | h::t -> h::(removelast t) | [] -> raise NotImplemented ;;
let pascal (max : int) : int list list = unfold (fun b -> (b, (List.append (1::(List.map2 (+) (removefirst b) (removelast b))) [1]))) (fun a -> max + 1 <= List.length a ) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (price, weight, calories, ingredients)) -> List.for_all (fun a -> not (List.exists (fun b -> b = a) allergens)) ingredients) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = List.fold_left (fun acc x -> acc ^ (Char.escaped x)) "" l ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0 ;;