text
stringlengths
0
601k
let string_explode (s : string) : char list = raise NotImplemented;;
let string_implode (l : char list) : string = let x = List.map Char.escaped l in String.concat "" x;;
let evens (max : int) : int list = let x = unfold (fun b -> (2*b, b+1)) (fun b -> ((max-1)/2) < b) 0 in if (List.length x) = 1 then [] else x let rec fib_aux n a b = if n = 0 then b else fib_aux (n-1) b (a+b) let fib_tl n = fib_aux n 0 1;;
let fib (max : int) : int list = unfold (fun b -> (fib_tl(b), b+1)) (fun b -> max <= fib_tl(b)) (0);;
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 c = String.get s in let d = String.length s in tabulate c d;;
let string_implode (l : char list) : string = let k = List.map Char.escaped l in List.fold_left (^) "" k ;;
let evens (max : int) : int list = let alt = fun b->(b,b+2) in let alt2 = (<=) max in unfold alt alt2 0;;
let fib (max : int) : int list = let function1 = fun (prevValue, currValue)-> (prevValue, (currValue, currValue+prevValue)) in let stop1 = fun (prevValue, currValue)-> max<=prevValue in unfold function1 stop1 (1, 1);;
let pascal (max : int) : int list list = let function1 = fun prevList -> (prevList, (let y = List.append prevList [0] in let z = List.append [0] prevList in List.map2 (+) y z )) in let stop1 = fun (prevList) -> List.length prevList > max in unfold function1 stop1 [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec x (allergens: ingredient list) (cup: cupcake) : bool = let Cupcake (a,b,d,c) = cup in match c with | [] -> false | hd::tl -> if List.mem hd allergens then true else let h = Cupcake (a,b,d,tl) in x allergens h in let rec x2 (allergens: ingredient list)(cup: cupcake) : bool = let Cupcake (a,b,d,c) = cup in match c with | [] -> true | hd::tl -> if (List.mem hd allergens && List.exists (x allergens) cupcakes) then false else let h = Cupcake (a,b,d,tl) in x2 allergens h in if (List.for_all (x allergens) cupcakes) then [] else List.filter (x2 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_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 (b_prev, b) -> (b, (b, b+b_prev))) (fun (b_prev, b) -> max <= b) (0, 1);;
let pascal (max : int) : int list list = unfold (fun l -> (l, (List.map2 (+) (l @ [0]) (0::l)) )) (fun l -> max < List.length l) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let f c = let Cupcake(price, weight, calories, ingredients_l) = c in let f' ingredient = not (List.exists (fun allergen -> allergen = ingredient) allergens) in List.for_all (f') (ingredients_l) in List.filter (f) (cupcakes);;
let find = function s -> function length -> (String.get s length);;
let string_explode (s : string) : char list = tabulate (find s) (String.length s);; let toStr = function (c:char) -> Char.escaped c;; let conc = fun (a:string) (b:string) -> String.concat "" [a;b];;
let string_implode (l : char list) : string = List.fold_left conc "" (List.map toStr l);;
let evens (max : int) : int list = unfold (fun a -> (a,2+a)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a, b) -> (a, (b, a+b))) (fun (a, b) -> max <= a) (1, 1);; let sum = fun (l: int list) -> List.map2 (+) (List.tl l) (List.rev (List.tl (List.rev l)));; let newline = fun (l:int list) -> List.append (List.append [1] (sum l)) [1];;
let pascal (max : int) : int list list = match max with | 0 -> [] | _ -> List.append [[1]] (unfold (fun (a,b) -> (b, (a,newline b))) (fun (a,b) -> (List.length b )> max) ([1],[1;1]));;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,ingredient) -> List.for_all (fun x -> not(List.exists (fun y -> y=x) allergens) ) ingredient) 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 = String.concat "" (List.map (Char.escaped)(l));;
let evens (max : int) : int list = let is_even (b : int) = match b mod 2 with | 0 -> b, b+1 | 1 -> 1, b+1 | _ -> 0,0 in List.filter (fun x -> x <> 1) (unfold (is_even)(fun b -> max <= b) 0 );;
let fib (max : int) : int list = unfold (fun (x, y) -> (x, (y, x+y))) (fun (a,b) -> a >= max) (1,1);;
let pascal (max : int) : int list list = let pascal_helper (l : int list) = (List.map2 (+)(l@[0])(List.rev(l@[0])) , List.map2 (+)(l@[0])(List.rev(l@[0]))) in if max > 0 then [1] :: unfold (pascal_helper)(fun l -> List.length(l) >= max) ([1]) else [];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ingr (c : cupcake) = match c with | Cupcake (price,weight,calories,ingredient_list) -> ingredient_list in List.filter (fun x -> not (List.for_all (fun c1 -> List.exists (fun x -> List.mem (x)(get_ingr(c1))) (allergens)) (cupcakes))) (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 String.concat "" ls ;;
let evens (max : int) : int list = unfold (fun b -> (b, b + 2)) ((<=) max) 0 ;;
let fib (max : int) : int list = unfold (fun (b1, b2) -> (b1, (b2, b1 + b2))) (fun (b1, b2) -> b1 >= max) (1, 1) ;;
let pascal (max : int) : int list list = let add_0 l = List.append l [0] in unfold (fun b -> (b, (List.map2 (+) (add_0 b) (List.rev (add_0 b))))) (fun b -> List.length b > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ingrelist (ck: cupcake) = let Cupcake (a,b,c,d) = ck in d in let check_allergens (ck: cupcake) : bool = let ingrelist = get_ingrelist ck in let bool_alt= (List.exists (fun i -> i = Nuts) allergens && not(List.for_all (fun i -> i != Nuts) ingrelist)) || (List.exists (fun i -> i = Gluten) allergens && not(List.for_all (fun i -> i != Gluten) ingrelist )) || (List.exists (fun i -> i = Soy) allergens && not(List.for_all (fun i -> i != Soy) ingrelist )) || (List.exists (fun i -> i = Dairy) allergens && not(List.for_all (fun i -> i != Dairy) ingrelist )) in not (bool_alt) in List.filter check_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 String.concat "" ls ;;
let evens (max : int) : int list = unfold (fun b -> (b, b + 2)) ((<=) max) 0 ;;
let fib (max : int) : int list = unfold (fun (b1, b2) -> (b1, (b2, b1 + b2))) (fun (b1, b2) -> b1 >= max) (1, 1) ;;
let pascal (max : int) : int list list = let add_0 l = List.append l [0] in unfold (fun b -> (b, (List.map2 (+) (add_0 b) (List.rev (add_0 b))))) (fun b -> List.length b > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_allergens (ck: cupcake) : bool = let get_ingrelist (ck: cupcake) = let Cupcake (a,b,c,d) = ck in d in let ingrelist = get_ingrelist ck in let bool_alt= (List.exists (fun i -> i = Nuts) allergens && not(List.for_all (fun i -> i != Nuts) ingrelist)) || (List.exists (fun i -> i = Gluten) allergens && not(List.for_all (fun i -> i != Gluten) ingrelist )) || (List.exists (fun i -> i = Soy) allergens && not(List.for_all (fun i -> i != Soy) ingrelist )) || (List.exists (fun i -> i = Dairy) allergens && not(List.for_all (fun i -> i != Dairy) ingrelist )) in not (bool_alt) in List.filter check_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 String.concat "" ls ;;
let evens (max : int) : int list = unfold (fun b -> (b, b + 2)) ((<=) max) 0 ;;
let fib (max : int) : int list = unfold (fun (b1, b2) -> (b1, (b2, b1 + b2))) (fun (b1, b2) -> b1 >= max) (1, 1) ;;
let pascal (max : int) : int list list = let add_0 l = List.append l [0] in unfold (fun b -> (b, (List.map2 (+) (add_0 b) (List.rev (add_0 b))))) (fun b -> List.length b > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_allergens (ck: cupcake) : bool = let get_ingrelist (ck: cupcake) = let Cupcake (a,b,c,d) = ck in d in let ingrelist = get_ingrelist ck in let bool_alt= (List.exists (fun i -> i = Nuts) allergens && not(List.for_all (fun i -> i != Nuts) ingrelist)) || (List.exists (fun i -> i = Gluten) allergens && not(List.for_all (fun i -> i != Gluten) ingrelist )) || (List.exists (fun i -> i = Soy) allergens && not(List.for_all (fun i -> i != Soy) ingrelist )) || (List.exists (fun i -> i = Dairy) allergens && not(List.for_all (fun i -> i != Dairy) ingrelist )) in not (bool_alt) in List.filter check_allergens cupcakes ;;
let string_explode (s : string) : char list = let length = String.length s in let list = tabulate (function n->n+1) length in let list2 = List.map (function n->n-1) list in let get_string = String.get s in List.map get_string list2;;
let string_implode (l : char list) : string = let q = List.map Char.escaped l in List.fold_left (^) "" q;;
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 = let get_next_row row = 1 :: unfold (function [] -> raise (Failure "empty set") | a :: [] -> a, [] | x :: y :: t -> x + y, y :: t ) (function l -> l = []) row in unfold (function row -> (row, get_next_row row)) (fun row -> List.length row >= max+1 ) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let q=function a-> List.for_all (function b -> a!=b) allergens == false in List.filter (function Cupcake (_,_,_,ingred_lst)->List.exists q ingred_lst==false) cupcakes;;
let string_explode (s : string) : char list = let f = String.get s in tabulate f (String.length s) ;;
let string_implode (l : char list) : string = let f = Char.escaped in String.concat "" (List.map f 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 pascal (max : int) : int list list = unfold (fun a -> (a, (List.map2 (+) (List.append a [0]) (List.append [0] a)))) (fun a -> List.length a > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let extract (cupc: cupcake) = let Cupcake (pr,wt,cl,ingre) = cupc in ingre in let check (cupc: cupcake) : bool = let ingredients = extract cupc in let remove = (not (List.for_all (fun x -> x != Nuts) allergens) && List.exists (fun x -> x = Nuts) ingredients) || (not (List.for_all (fun x -> x != Soy) allergens) && List.exists (fun x -> x = Soy) ingredients) || (not (List.for_all (fun x -> x != Dairy) allergens) && List.exists (fun x -> x = Dairy) ingredients) || (not (List.for_all (fun x -> x != Gluten) allergens) && List.exists (fun x -> x = Gluten) ingredients) in not (remove) in List.filter check cupcakes ;;
let string_explode (s : string) : char list = let f = String.get s in tabulate f (String.length s) ;;
let string_implode (l : char list) : string = let f = Char.escaped in String.concat "" (List.map f l) ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 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 a -> (a, (List.map2 (+) (List.append a [0]) (List.append [0] a)))) (fun a -> List.length a > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let extract = fun (Cupcake (pr,wt,cl,ingre)) -> ingre in let check (cupc: cupcake) : bool = let ingredients = extract cupc in let remove = (not (List.for_all (fun x -> x != Nuts) allergens) && List.exists (fun x -> x = Nuts) ingredients) || (not (List.for_all (fun x -> x != Soy) allergens) && List.exists (fun x -> x = Soy) ingredients) || (not (List.for_all (fun x -> x != Dairy) allergens) && List.exists (fun x -> x = Dairy) ingredients) || (not (List.for_all (fun x -> x != Gluten) allergens) && List.exists (fun x -> x = Gluten) ingredients) in not (remove) in List.filter check cupcakes ;;
let string_explode (s : string) : char list = let f = String.get s in tabulate f (String.length s) ;;
let string_implode (l : char list) : string = let f = Char.escaped in String.concat "" (List.map f l) ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 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 a -> (a, (List.map2 (+) (List.append a [0]) (List.append [0] a)))) (fun a -> List.length a > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let extract = fun (Cupcake (pr,wt,cl,ingre)) -> ingre in let check (cupc: cupcake) : bool = let ingredients = extract cupc in let remove = (not (List.for_all (fun x -> x != Nuts) allergens) && List.exists (fun x -> x = Nuts) ingredients) || (not (List.for_all (fun x -> x != Soy) allergens) && List.exists (fun x -> x = Soy) ingredients) || (not (List.for_all (fun x -> x != Dairy) allergens) && List.exists (fun x -> x = Dairy) ingredients) || (not (List.for_all (fun x -> x != Gluten) allergens) && List.exists (fun x -> x = Gluten) ingredients) in not (remove) in List.filter check cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = let (+++) x y = String.concat "" [(Char.escaped x); y] in List.fold_right (+++) l "";;
let evens (max : int) : int list = let gen_next_seed (seed : int) : int * int = ((2 * seed), (seed + 1)) in unfold gen_next_seed (fun x -> 2 * x >= max) 0;;
let fib (max : int) : int list = let get_next_val (x, y) : (int * (int*int)) = ((x + y), (y, (x + y))) in if max < 2 then [] else 1 :: 1 :: unfold get_next_val (fun (x, y) -> (x + y) >= max) (1, 1);;
let pascal (max : int) : int list list = let next_level (seed : int list) = let new_level = let seed_zero = List.rev(0::List.rev(seed)) in List.map2 (+) seed_zero (0::seed) in (new_level, new_level) in if max < 0 then raise NotImplemented else if max = 0 then [] else if max = 1 then [[1]] else [1]::(unfold next_level (fun b -> (List.length b) >= max) [1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let cake_has_ing alg_ings (Cupcake (x,y,z,ings)) = List.for_all ( fun ing -> not (List.exists (fun i -> i = ing) ings) ) alg_ings in List.filter (cake_has_ing allergens) cupcakes ;;
let string_explode (s : string) : char list = tabulate (fun i -> String.get s i) (String.length s);;
let string_implode (l : char list) : string = List.fold_right (^) (List.map (fun a -> Char.escaped a) l) "" ;;
let evens (max : int) : int list = unfold (fun a -> (a, a+2)) (fun a -> max <= a) 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 a -> (a, List.map2 (+) (List.cons 0 a) (List.rev (List.cons 0 a)) )) (fun a -> List.length a > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let helper1 (cake: cupcake) (allergen : ingredient) : bool = not (List.exists (fun a -> a = allergen) (extract cake) ) in let helper2 (cake: cupcake) (a_list: ingredient list): bool = List.for_all (fun a -> helper1 cake a) a_list in List.filter (fun a -> helper2 a allergens) cupcakes ;;
let string_explode (s : string) : char list = tabulate (fun a -> String.get s a) (String.length s) ;;
let string_implode (l : char list) : string = let (s_list : string list) = List.map (fun x -> Char.escaped x) l in List.fold_left (fun cur_str next_char -> cur_str ^ next_char) "" s_list ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0 ;;
let fib (max : int) : int list = let t = (1, 1) in unfold (fun b -> (fst(b), (snd(b), snd(b) + fst(b)))) (fun b -> max <= fst(b)) t ;;
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 cupcakes else if List.length cupcakes == 0 then [] else List.filter (fun cup -> let Cupcake(_,_,_,ingredients) = cup in if List.length ingredients == 0 then true else List.for_all (fun a -> not(List.exists (fun z -> z==a) allergens))ingredients) 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 = List.fold_right (fun x y-> (Char.escaped x) ^ y) 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 (prev,cur) -> (prev),(cur, prev+cur)) (fun (prev,cur) -> max <= prev) (1,1);;
let pascal (max : int) : int list list = let getRow (l: int list) : int list= let (_ :: l1) = l in let (_ :: l2) = List.rev l in let l3= List.append [1] (List.map2 (+) l1 l2) in List.append l3 [1] in unfold (fun l -> getRow([l]),l) (fun l -> max <= List.length (getRow([1]))) 1;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check1 (Cupcake (_,_,_,i), l) : bool= List.exists(fun x-> List.for_all(fun z-> not (List.mem z l) ) i) l in if List.length allergens = 0 then cupcakes else List.filter (fun c -> check1(c, allergens)) cupcakes;;
let string_explode (s : string) : char list = let listOfInts = tabulate (fun x -> x) (String.length s) in List.map (String.get s) listOfInts;;
let string_implode (l : char list) : string = let charList = List.map Char.escaped l in List.fold_right (^) charList "";;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0;;