text
stringlengths
0
601k
let string_explode (s : string) : char list = tabulate(function (x)-> (String.get s x)) (String.length s);;
let string_implode (l : char list) : string = List.fold_right(fun x y -> x ^ y) (List.map(fun x -> Char.escaped x) 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 = unfold(fun(ls) -> (ls, List.map2 (+) (0 :: ls) (ls @[0]))) (fun(ls) -> List.length ls > max) ([1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake(_,_,_,ingredient_list) -> List.for_all ((fun ing -> not(List.exists (fun allergen -> allergen = ing) allergens ))) ingredient_list ) 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 = String.concat "" (List.map (Char.escaped) l);;
let evens (max : int) : int list = let next i = i + 2 in unfold (fun n -> n, next n) (fun n -> max <= n) 0;;
let fib (max : int) : int list = let next nums = let n1 = List.nth nums 0 in let n2 = List.nth nums 1 in [n2; n1 + n2] in unfold (fun nums -> List.nth nums 0, next nums) (fun num2 -> max <= (List.nth num2 0)) [1; 1];;
let pascal (max : int) : int list list = unfold (fun (line_n, line_v) -> if List.length line_v = 0 then [1], (line_n + 1, [1]) else let line_v = List.(line_v @ [0] |> tl |> map2 (+) line_v |> cons 1) in line_v, (line_n + 1, line_v)) (fun line_v -> max <= fst line_v) (0, []);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) = List.filter (fun (Cupcake(price, weight, calories, ingredients)) -> List.for_all (fun a -> not (List.exists (fun x -> x = a) allergens)) ingredients ) cupcakes;;
let string_explode (s : string) : char list = let n = String.length s in tabulate (String.get s) n;;
let string_implode (l : char list) : string = List.fold_left (fun a b -> a^ (Char.escaped b)) "" l;;
let evens (max : int) : int list = unfold (fun x -> if x mod 2 == 0 then (x, x+2) else (x+1, x+3)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (x,y) -> (y, (y, x+y))) (fun (x,y) -> max <= y) (0,1);;
let pascal (max : int) : int list list = let compute_row l1 = if List.length l1 = 1 then 1 :: l1 else let (_::l1_no_head) = l1 in let (_::l1_no_tail) = List.rev l1 in let l1_no_tail = List.rev l1_no_tail in [1] @ (List.map2 (+) l1_no_tail l1_no_head) @ [1] in unfold (fun l -> (l, compute_row (l))) (fun x -> List.length x > max) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ingredient cupcake = let Cupcake (_, _, _, ingredients) = cupcake in ingredients in List.filter (fun cupcake -> List.for_all (fun allergy -> not (List.exists (fun ingredient -> ingredient = allergy ) (get_ingredient cupcake))) allergens) cupcakes;;
let string_explode (s : string) : char list = let create_index (a : int) = a in let string_length = String.length(s) in let index_list = tabulate create_index string_length in let get_char index = String.get s index in List.map get_char index_list;;
let string_implode (l : char list) : string = let final_string = "" in let c_to_s (l : char list) = List.map Char.escaped l in let s_list = c_to_s (l) in List.fold_left (^) final_string s_list;;
let evens (max : int) : int list = let stop current = current >= max in let f current = (current, current + 2) in unfold f stop 0;;
let fib (max : int) : int list = let stop (a, b) = if max = 1 then true else (a + b >= max) in let f (a, b) = if b = 0 then (1, (0, 1)) else (a + b, (b, a + b)) in unfold f stop (0, 0);;
let pascal (max : int) : int list list = let stop current = List.length(current) >= max in let next_pascal current = let a = [0] @ current in let b = current @ [0] in List.map2 (+) a b in let f current = if List.length(current) = 0 then ([1], [1]) else (next_pascal(current), next_pascal(current)) in unfold f stop [];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ingredients c = let Cupcake (price,weight,calories,ing_list) = c in ing_list in let filter_check c = let ing_list = get_ingredients c in let for_all_check allergen = let exists_check a = a = allergen in List.exists exists_check ing_list in List.for_all for_all_check allergens in List.filter filter_check cupcakes;;
let string_explode (s : string) : char list = let len = String.length s in tabulate (String.get s) len;;
let string_implode (l : char list) = let str_lst = List.map (Char.escaped) l in List.fold_left (^) "" str_lst;;
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, (b, a+b))) (fun (a,b) -> max <= (a+b)) (1,0);;
let pascal (max : int) : int list list = unfold (fun a -> (a, List.map2 (+) (0 :: a) (a @ [0]))) (fun a -> max < List.length a) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) = List.filter (function Cupcake (_, _, _, x) -> List.for_all (fun y -> not (List.exists(fun z -> z = y) allergens)) x) cupcakes;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = match l with | [] -> "" | _ -> begin let stringList = List.map Char.escaped l in List.fold_left (^) (List.hd stringList) (List.tl stringList) end;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = let aux = fun b -> fst b, (snd b, ((fst b) + (snd b))) in unfold (aux) (fun b -> max <= fst b) (1, 1);;
let pascal (max : int) : int list list = let aux b = let cur = ((snd b) * (fst(fst b) - snd(fst b) + 1)) / snd(fst b) in cur, ((fst(fst b), (snd(fst b) + 1)), cur) in let rowC c = 1::unfold (aux) (fun b -> c < snd(fst b)) ((c, 1), 1) in unfold (fun b -> (rowC b, b + 1)) ((<=) max) 0;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_allergens ingredient = not (List.exists (fun allergen -> allergen = ingredient) allergens) in let aux el = let Cupcake (price, weight, calories, ingredients_list) = el in List.for_all (check_allergens) ingredients_list in List.filter (aux) 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) -> (a, (b, a+b))) (fun (a, b) -> a > (max-1)) (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];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun x -> let Cupcake (_,_,_,ingred_lst) = x in List.for_all (fun x -> not (List.exists (fun y->y=x) ingred_lst)) allergens ) cupcakes ;;
let string_explode (s : string) : char list = let getChar n = String.get s n in tabulate getChar (String.length s);;
let string_implode (l : char list) : string = let listOfStrings = List.map Char.escaped l in List.fold_left (^) ("") (listOfStrings);;
let evens (max : int) : int list = unfold (fun n -> (n, n+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 = raise NotImplemented;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ingredient_list (this_cake : cupcake) = let Cupcake (_, _, _, ingredients) = this_cake in ingredients in let cupcake_has_no_allergen (this_cake : cupcake) : bool = List.for_all (fun ingredient -> ( not (List.exists (fun allergen -> allergen = ingredient ) (allergens) ))) (get_ingredient_list this_cake) in List.filter (cupcake_has_no_allergen) (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 -> (b, b+2)) (fun b -> max <= b) 0;;
let fib (max : int) : int list = if max == 0 || max == 1 then [] else [1] @ unfold (fun b -> (snd b, (snd b, fst b + snd b))) (fun b -> max <= snd b) (1, 1);;
let pascal (max : int) : int list list = raise NotImplemented;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if List.length allergens > 0 then List.filter (fun x -> List.for_all (fun b -> not(List.exists (fun z -> z == b) allergens)) (ingredient_list x)) cupcakes else cupcakes ;;
let string_explode (s : string) : char list = let l = String.length s in tabulate (String.get s) l ;;
let string_implode (l : char list) : string = List.fold_left ( fun acc e2 -> acc ^ (Char.escaped e2) ) "" l ;;
let evens (max : int) : int list = let stop = (<=) max in unfold(fun b -> (b, b+2)) stop (0) ;;
let fib (max : int) : int list = let stop (a,b) = a >= max in unfold (fun (b1, b2) -> (b1, (b2, b1+b2))) stop (1,1) ;;
let pascal (max : int) : int list list = let add (row : int list) = (row, List.map2 (+) (0 :: row) (row @ [0])) in let stop (row : int list) = max < List.length row in unfold add stop [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let exist_allergic = List.exists (fun x -> List.mem x allergens) in let all_not_allergic = fun ls -> let exist_or_not = exist_allergic ls in List.for_all (fun x -> not(exist_or_not)) ls in let check_ingredient_list (c : cupcake) = match c with |Cupcake(price, weight, calories, ingredient) -> all_not_allergic ingredient |_ -> true in let filter_not_allergic = List.filter (check_ingredient_list) in filter_not_allergic cupcakes ;;
let string_explode (s : string) : char list = let l = String.length s in tabulate (String.get s) l ;;
let string_implode (l : char list) : string = List.fold_left ( fun acc e2 -> acc ^ (Char.escaped e2) ) "" l ;;
let evens (max : int) : int list = let stop = (<=) max in unfold(fun b -> (b, b+2)) stop (0) ;;
let fib (max : int) : int list = let stop (a,b) = a >= max in unfold (fun (b1, b2) -> (b1, (b2, b1+b2))) stop (1,1) ;;
let pascal (max : int) : int list list = let add (row : int list) = (row, List.map2 (+) (0 :: row) (row @ [0])) in let stop (row : int list) = max < List.length row in unfold add stop [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let exist_allergic = List.exists (fun x -> List.mem x allergens) in let all_not_allergic = fun ls -> let exist_or_not = exist_allergic ls in List.for_all (fun x -> not(exist_or_not)) ls in let check_ingredient_list (c : cupcake) = match c with |Cupcake(price, weight, calories, ingredient) -> all_not_allergic ingredient |_ -> true in let filter_not_allergic = List.filter (check_ingredient_list) in filter_not_allergic cupcakes ;;
let string_explode (s : string) : char list = let length = String.length s in tabulate (String.get s) length;;
let string_implode (l : char list) : string = let isString = List.map Char.escaped l in String.concat "" isString;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = if max = 0 || max = 1 then [] else let preFib = unfold (fun (a,b) -> (a+b,(b,a+b))) (fun (a,b) -> max <= a+b) (0,1) in let preFibrev = List.rev preFib in List.rev (preFibrev@[1]);;
let pascal (max : int) : int list list = let list1 = [1] in unfold (fun b -> (b, List.map2 (+) (List.rev (b@[0])) (b@[0]))) (fun b -> max < List.length b) list1;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let allergy_check (listAllerg : ingredient list) oneIngredient : bool = let theIngredient = oneIngredient in not (List.exists (fun(x) -> x == theIngredient) listAllerg) in let filtering initial modified = let helper x : bool = List.mem x modified in List.filter helper initial in let allergy_check2 allergens cupcake = let invalid = Cupcake (0., 0., 0, [])in let helper x : bool = allergy_check allergens x in let safe = List.for_all helper (ingredient_getter cupcake) in if (safe) then cupcake else invalid in let helper = allergy_check2 allergens in let unfiltered = List.map helper cupcakes in filtering cupcakes unfiltered;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = l |> List.map Char.escaped |> List.fold_left (^) "";;
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, _) -> max <= a) (1, 1);;
let pascal (max : int) : int list list = unfold (fun b -> let l1 = 0 :: b in let l2 = b |> List.rev |> List.cons 0 |> List.rev in (b, List.map2 (+) l1 l2)) (fun b -> max < (List.length b)) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let no_allergens (Cupcake(_, _, _, ings)) = let is_allergen ing = List.exists (fun al -> al = ing) allergens in List.for_all (fun ing -> not (is_allergen ing)) ings in List.filter no_allergens 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 = List.fold_left (fun a b -> a ^ (Char.escaped b)) "" 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, _) -> max <= a) (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_left (fun a b -> a ^ (Char.escaped b)) "" 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, _) -> max <= a) (1, 1);;
let pascal (max : int) : int list list = unfold (fun b -> (b, List.map2 (+) (List.tl b) (List.rev b |> List.tl |> List.rev))) (List.for_all ((<=) max)) [0; 1; 0];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_allergen ingredient = List.exists (fun al -> al = ingredient) allergens in let allergens_free = List.for_all (fun ing -> not (is_allergen ing)) in List.filter (fun (Cupcake(_, _, _, ingredients)) -> allergens_free ingredients) cupcakes;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = l |> List.map Char.escaped |> List.fold_left (^) "";;
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, _) -> max <= a) (1, 1);;
let pascal (max : int) : int list list = unfold (fun b -> let l1 = 0 :: b in let l2 = b |> List.rev |> List.cons 0 |> List.rev in (b, List.map2 (+) l1 l2)) (List.exists ((<=) max)) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let no_allergens (Cupcake(_, _, _, ingredients)) = let is_allergen ingredient = List.exists (fun al -> al = ingredient) allergens in List.for_all (fun ing -> not (is_allergen ing)) ingredients in List.filter no_allergens cupcakes;;
let string_explode (s : string) : char list = let f = fun n -> (String.get s n) in tabulate f (String.length s);;
let string_implode (l : char list) : string = let mylist = (List.map (fun x -> "" ^ Char.escaped x) l) in String.concat "" mylist;;
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);;