text
stringlengths
0
601k
let pascal (max : int) : int list list = unfold (fun row -> (row, (List.map2 (+) (0 :: row) (row @ [0])))) (fun row -> max <= (List.length row)-1) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if List.exists (fun x -> true) cupcakes then List.filter (function (Cupcake (_,_,_,ingredient_list)) -> List.for_all (fun ingredient -> List.for_all ((!=) ingredient) ingredient_list) allergens) cupcakes else cupcakes;;
let string_explode (s : string) : char list = let l = tabulate (fun x -> x) (String.length s) in List.map (String.get s) l ;;
let string_implode (l : char list) : string = let l2= List.map Char.escaped l in List.fold_left (^) "" l2 ;;
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 = let get_l1 l = 0 :: l in let get_l2 l = List.rev ( 0 :: (List.rev l)) in unfold (fun (l : int list) -> (l , (List.map2 (+) (get_l1 l) (get_l2 l) ))) (fun (l : int list) -> max < List.length l) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_ingredient (c : cupcake) :bool = let Cupcake (p,w,c,l) = c in List.for_all ( fun x -> not( List.exists (fun y -> y = x) allergens)) l in List.filter check_ingredient cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = let char_to_str = String.make 1 in List.fold_left (^) (String.make 0 'a') (List.map char_to_str l);;
let evens (max : int) : int list = let even x = (x, x + 2) in unfold even ((<=) max) 0;;
let fib (max : int) : int list = let rec fib_aux = function | 0 -> 1 | 1 -> 1 | n -> fib_aux (n - 1) + fib_aux (n - 2) in unfold (fun n -> (fib_aux n, n + 1)) (fun n -> max <= (fib_aux n)) 0;;
let pascal (max : int) : int list list = let pairs l = (List.combine (List.rev (List.tl (List.rev l))) (List.tl l)) in let rec pas = function | 0 -> [1] | 1 -> [1;1] | n -> (1 :: List.map (fun (a, b) -> a + b) (pairs (pas (n - 1)))) @ [1] in unfold (fun n -> (pas n, n + 1)) (fun n -> max < (List.length (pas n))) 0;;
let zip (l1 : 'a list) (l2 : 'b list) : ('a * 'b) list = let smaller a b = if (List.length a) < (List.length b) then List.length a else List.length b in let combine a b n = (List.nth a n, List.nth b n) in unfold (fun n-> (combine l1 l2 n, n + 1)) (fun n -> n = (smaller l1 l2)) 0;;
let allergy_free = function | Cupcake(_,_,_,[]) -> true | Cupcake(_,_,_,a) -> List.for_all (not) (allerg_test a) in List.filter (allergy_free) cupcakes;;
let string_explode (s : string) : char list = let l1 = tabulate (fun x -> x) (String.length(s)) in List.map (String.get s) l1 ;;
let string_implode (l : char list) : string = let l1 = List.map Char.escaped l in String.concat "" l1;;
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 (l1:int list) -> (l1, (List.map2 (+) (l1@[0]) (0 :: l1)))) (fun l1 -> max < List.length l1) ([1]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec helper (c5:cupcake) = match c5 with | Cupcake (_, _, _, []) -> true | Cupcake (_, _, _, l) -> let isMem x = List.mem x allergens in not (List.exists (isMem) l || List.for_all (isMem) l) in List.filter(helper) 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) ((<=) 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 l -> (l, 1 :: (List.map2 (+) 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, cals, ingredients)) -> List.for_all (fun i -> not (List.exists (fun j -> j = i) allergens)) ingredients) cupcakes;;
let string_explode (s : string) : char list = match s with "" -> [] | _ -> tabulate(String.get s)(String.length s) ;;
let string_implode (l : char list) : string = match l with [] -> "" | _ -> 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 (a,b) = (1,1) in unfold (fun (m,n) -> (m, (n, m+n))) (fun (m, n) -> max <= m) (a,b);;
let pascal (max : int) : int list list = let start = [1] in unfold (fun a -> (a, List.map2 (+) (a @ [0]) (0 :: a))) (fun b -> max <= List.length(b) - 1) (start) ;; let helperstop l1 l2 = match l1, l2 with [], _ -> true |_, [] -> true | _,_ -> false ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let inner = fun t -> (not ( List.exists(fun p -> p = t) (allergens))) in let arg1 = fun ck -> List.for_all(inner) (helper ck) in let arg2 = cupcakes in List.filter arg1 arg2 ;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = List.fold_right (^) (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,c) -> (a,(b, c, b+c))) (fun (a,b,c) -> max <= a) (1,1,2);;
let pascal (max : int) : int list list = unfold (fun prev -> (prev,(List.map2 (+) (0 :: prev) (List.append prev [0])))) (fun prev -> max+1 <= (List.length prev)) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let checkIng ingredient = not (List.exists ((=) ingredient) allergens) in let checkCupcake cupcake = let Cupcake (price, weight, calories ,ingredients) = cupcake in List.for_all checkIng ingredients in List.filter checkCupcake 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)) ((<=) max) 0;;
let fib (max : int) : int list = if max <= 1 then [] else( 1::1:: unfold (fun (a,b) -> (a + b, (b, a + b))) (fun (a,b) -> max <= a+b) (1, 1) );;
let pascal (max : int) : int list list = if max <= 0 then [] else( [1] :: unfold (fun row -> (let list1 = 0::row in let list2 = List.rev (0:: (List.rev row)) in let sum_of_rows = List.map2 (+) list1 list2 in (sum_of_rows, sum_of_rows))) (fun row -> max <= List.length row) [1] );;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let allergy_check (restrictions: 'a list) (cup_cake: cupcake) : bool = let Cupcake(p, w, c, cup_ingredients) = cup_cake in List.for_all (fun x -> not (List.exists (fun a -> a == x) cup_ingredients)) restrictions in List.filter (allergy_check allergens) cupcakes;;
let string_explode (s : string) : char list = let map_to_char (n : int) = String.get s n in tabulate map_to_char (String.length s) ;;
let string_implode (l : char list) : string = let helper (b : char) (s : string) : string = Char.escaped b ^ s in List.fold_right helper l "" ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> b >= max) 0 ;;
let fib (max : int) : int list = let helper (r : (int * int)) = let (n, n1) = r in (n, (n1, n+n1)) in unfold helper (fun a -> let (n, n1) = a in n >= max) (1, 1) ;;
let pascal (max : int) : int list list = let helper (l : int list) = (l, List.map2 (+) (0::l) (List.append l [0])) in unfold helper (fun l -> (List.length l) > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun cupcake -> let Cupcake (_, _, _, ingredients) = cupcake in List.for_all (fun ingredient -> not (List.exists ((=) ingredient) allergens)) ingredients) cupcakes ;;
let string_explode (s : string) : char list = let map_to_char (n : int) = String.get s n in tabulate map_to_char (String.length s) ;;
let string_implode (l : char list) : string = let helper (b : char) (s : string) : string = Char.escaped b ^ s in List.fold_right helper l "" ;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> b >= max) 0 ;;
let fib (max : int) : int list = let helper (r : (int * int)) = let (n, n1) = r in (n, (n1, n+n1)) in unfold helper (fun a -> let (n, n1) = a in n >= max) (1, 1) ;;
let pascal (max : int) : int list list = let helper (l : int list) = (l, List.map2 (+) (0::l) (List.append l [0])) in unfold helper (fun l -> (List.length l) > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun cupcake -> let Cupcake (_, _, _, ingredients) = cupcake in List.for_all (fun ingredient -> not (List.exists ((=) ingredient) allergens)) ingredients) cupcakes ;;
let string_explode (s : string) : char list = let stringlength = String.length(s) in tabulate (String.get(s)) (stringlength) ;;
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)) ((<=) max) 0 ;;
let fib (max : int) : int list = let func1 = fun (x,y) -> (x, (y, x+y)) in let func2 = fun (x,y) -> max <= x in unfold (func1) (func2) (1,1) ;;
let pascal (max : int) : int list list = let func1 = fun a -> (a, List.map2 (+) (a @ [0]) (0 :: a)) in let func2 = fun b -> max <= List.length(b) - 1 in unfold (func1) (func2) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let func2 (c : cupcake) = let Cupcake(x,y,z, ingredients) = c in ingredients in let func1 = fun c -> (List.for_all(fun i -> (not (List.exists (fun a -> a = i) allergens)))(func2 c)) in List.filter (func1) (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 |[] -> "" |_ -> let a = List.map Char.escaped l in String.concat "" a;;
let evens (max : int) : int list = if max < 0 then failwith "error input" else unfold (fun b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = if max < 0 then failwith "error input" else unfold (fun (a,b) -> (a, (b,a+b))) (fun (a,b) -> max <= a) (1,1);;
let pascal (max : int) : int list list = match max with |0 -> [] |_ -> [1] :: unfold (fun (b,l) -> ((List.map2 (+) (0 :: l) (l@[0]))), (b+1,(List.map2 (+) (0::l) (l@[0])))) (fun (b,l) -> max <= b) (1,[1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,allergy) -> List.for_all (fun y -> not (List.exists( fun x -> x = y) allergens)) allergy) cupcakes ;;
let string_explode (s : string) : char list = let to_char (s : string) (n : int) = String.get s n in tabulate (to_char s) (String.length s) ;;
let string_implode (l : char list) : string = let string_list = List.map (Char.escaped) (l) in List.fold_right (^) string_list "" ;;
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 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 = let ing_check_all allergens single_cupcake = let Cupcake (_,_,_,ingred_list) = single_cupcake in let ing_check_single (allergens : ingredient list) (ingr : ingredient) = not (List.exists (fun a_ingr -> a_ingr = ingr ) allergens) in List.for_all (ing_check_single allergens) (ingred_list) in List.filter (ing_check_all allergens) cupcakes ;;
let string_explode (s : string) : char list = tabulate (function x -> s.[x]) (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 a -> (a, a + 2)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a,b) -> (a, (b,b+a)))(fun (a,b) -> max <= a) (1,1);;
let pascal (max : int) : int list list = unfold (fun l-> l, (List.map2 (+) (0::l) (l@[0]))) (fun l -> List.length l >max) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = match allergens, cupcakes with | [], _ -> cupcakes | _, [] -> [] | allergens, cupcakes -> List.filter ((function mycupcake -> match mycupcake with | Cupcake(price, weight, calories, []) -> true | Cupcake(price, weight, calories, ingred) -> List.for_all ( function i -> not (List.exists ( function all -> all = i) allergens)) ingred)) 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 fib_num (a, b) = if (a, b) = (1,0) then (1, (0, 1)) else (a+b, (b, a+b)) in unfold (fib_num) (fun (a,b) -> max <= a+b) (1,0);;
let pascal (max : int) : int list list = let next_row lst = match lst with | [] -> ([1], [1]) | _::tl -> if (List.length lst) = 1 then ([1; 1], [1; 1]) else ((1 :: (List.map2 (+) lst (tl @ [0]))), (1 :: (List.map2 (+) lst (tl @ [0])))) in unfold (next_row) (fun lst -> max <= List.length lst) [];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let safe cupcake_ = let Cupcake (_, _, _, lst) = cupcake_ in (List.for_all (fun ingredient_ -> not (List.exists (fun b -> (b = ingredient_) ) allergens)) lst) in List.filter safe cupcakes;;
let string_explode (s : string) : char list = let length = String.length s in tabulate (fun (index: int) -> (String.get s index)) length;;
let string_implode (l : char list) : string = let init = "" in List.fold_right (fun (c: char) (str: string) -> String.make 1 c ^ str) l init;;
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 b -> ( List.hd (List.tl (List.rev b)), [List.hd (List.rev b); List.hd (List.rev b) + List.hd (List.tl (List.rev b))])) (fun b -> max <= List.hd b) [1; 1] let compute_next_row origin : int list = let l = List.hd (List.rev origin) in let l1 = List.rev (List.tl l) in let l2 = List.tl l in let list_wo_ones = List.map2 (+) l1 l2 in let right_one = list_wo_ones @ [1] in [1] @ right_one;;
let pascal (max : int) : int list list = match max with | 0 -> [] | 1 -> [[1]] | 2 -> [[1]; [1; 1]] | _ -> let f1 = (fun (b: int list list) -> b @ [(compute_next_row b)], b @ [(compute_next_row b)]) in let f2 = (fun b -> let (row_num: int) = List.hd (List.tl (List.hd (List.rev b))) in max <= row_num+1) in let (l: int list list) = [[1]; [1; 1]] in let bruh = unfold f1 f2 l in List.hd (List.rev bruh);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec contains_allergens (ingredients: ingredient list) (allergens: ingredient list) : bool = match allergens with | [] -> false | x:: xs -> if not (List.exists (fun ingr -> ingr = x) ingredients) then contains_allergens ingredients xs else true in let filter_cakes (cupcakes: cupcake list) (allergens: ingredient list) = List.filter (fun cake -> let Cupcake (_, _, _, ingr) = cake in not (contains_allergens ingr allergens)) cupcakes in if List.for_all (fun cake -> let Cupcake (_, _, _, ingr) = cake in not (contains_allergens ingr allergens)) cupcakes then cupcakes else filter_cakes cupcakes allergens;;
let string_explode (s : string) : char list = let string_getter (n:int) : 'a = String.get s n in tabulate string_getter (String.length s) let rec string_implode (l : char list) : string = let string_list=(List.map Char.escaped l) in let folder (s1:'a ) (s2:'b ) : 'a = s1^s2 in List.fold_left folder "" string_list;;
let evens (max : int) : int list = let stoper (seed : 'seed) : bool = (seed>=max) in let prevEve (seed : 'seed) : 'a * 'seed = (seed,(seed+2)) in unfold prevEve stoper 0;;
let fib (max : int) : int list = let stoper ( (f1,f2) : 'seed) : bool = (f1>=max) in let prevEve ( (f1,f2) : 'seed) : 'a * 'seed = (f1,(f2,f1+f2)) in unfold prevEve stoper (1,1);;
let pascal (max : int) : int list list = let stoper ( l1 : 'seed) : bool = ((List.length l1)>max) in let prevEve ( l1 : 'seed) : 'a * 'seed = ( l1,(List.map2 (+) (0::l1) (l1 @ [0]) )) in unfold prevEve stoper [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ingredient_in_allergens ingredient = not (List.exists (fun a -> a == ingredient) allergens) in let cupcake_is_clean cupcake = let Cupcake (price,weight,calories,ingredient)= cupcake in List.for_all ingredient_in_allergens ingredient in List.filter cupcake_is_clean cupcakes;;
let string_explode (s : string) : char list = match s with | "" -> [] | _ -> let length = String.length s in tabulate (String.get s) length;;
let string_implode (l : char list) : string = match l with | [] -> "" | _ -> let char_to_string = List.map Char.escaped l in List.fold_left (^) "" char_to_string;;