text
stringlengths
0
601k
let fib (max : int) : int list = let helper (a,b) = a,(b,a+b) in unfold helper (fun (a,b) -> a >= max) (1,1);;
let pascal (max : int) : int list list = let helper a = (a,(List.map2 (+) (0 :: a) (List.append a [0]))) in unfold helper (fun b -> (List.length b - 1) >= max) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let checkIngredients cupcake = let Cupcake (price, weight, calories, ingredients) = cupcake in List.for_all ( fun ingredient -> match List.exists ((==) ingredient ) allergens with true -> false | false -> true ) ingredients in List.filter checkIngredients 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 (^) (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) -> max <= a) (1,1);;
let pascal (max : int) : int list list = unfold (fun prev_row -> if prev_row = [1] then (prev_row, [1;1]) else (prev_row, (List.concat [[1]; (List.map2 (+) (List.tl prev_row) (List.rev (List.tl (List.rev prev_row)))); [1]]))) (fun prev_row -> max < (List.length prev_row)) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun cup -> let Cupcake (p,w,cal,ing_list) = cup in List.for_all (fun all -> not (List.exists (fun ing -> ing = all) ing_list)) allergens) 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) : 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 = unfold (fun b -> let (a', b') = b in (b', (b', a' + b')) ) (fun b -> let (a', b') = b in max <= b' ) (0, 1) ;;
let pascal (max : int) : int list list = unfold (fun row -> (row, List.map2 (+) (0 :: row) (row @ [0])) ) (fun row -> max < List.length row ) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( fun c -> let Cupcake (price, weight, calories, ingredients) = c in List.for_all ( fun i -> not (List.exists ( fun a -> a = i ) allergens) ) ingredients ) cupcakes ;;
let string_explode (s : string) : char list = let aux (s: string) (idx: int) = String.get s idx in List.map (aux s) (tabulate (fun x -> x) (String.length s));;
let string_implode (l : char list) : string = let aux (c: char) (acc: string) = (Char.escaped c) ^ acc in List.fold_right aux 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 = raise NotImplemented;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_safe (i: ingredient) = not (List.exists (fun x -> x=i) allergens) in let check (c: cupcake) = match c with | Cupcake (_, _, _, recipe) -> List.for_all is_safe recipe in List.filter check cupcakes;;
let string_explode (s : string) : char list = let q=tabulate (fun x -> (String.get s x)) (String.length s) in q;;
let string_implode (l : char list) : string = let list= tabulate (fun x -> Char.escaped (List.nth l x)) (List.length l) in let q= String.concat("") (list) in q;;
let evens (max : int) : int list = unfold (fun x -> (x, x+2)) (fun x -> max <= x) 0;;
let fib (max : int) : int list = unfold (fun x -> (x,(x+1)))(fun x -> max<=x) 1;;
let pascal (max : int) : int list list = let q=unfold (fun [x] -> [x], [x+1])(fun x -> max <=List.length x) [] in q;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let listofingredients c=let Cupcake(_,_,_,ingredient_list)= c in ingredient_list in let pred= List.mem (List.nth allergens 0) in if List.for_all pred (List.map listofingredients cupcakes) then [] else if not(List.exists pred (List.map listofingredients cupcakes)) then cupcakes else let j=List.filter pred (List.map listofingredients cupcakes) in cupcakes;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = let convert_string l = List.map (Char.escaped) l in String.concat "" (convert_string l);;
let evens (max : int) : int list = unfold (fun x -> (x, x+2)) (fun x -> max <= x) 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 = 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 (function Cupcake (_,_,_,ingredients) -> List.for_all (fun i -> not (List.exists (fun a -> a = i ) allergens)) ingredients) cupcakes;; |Cupcake(_, _, _, ingredients) -> List.exists (find_allergen a) ingredients; in List.filter (List.for_all (good_gakes x) allergens) cupcakes;; *);;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s) ;;
let string_implode (l : char list) : string = let append_char_to_str (s: string) (c: char) : string = s ^ (Char.escaped c) in List.fold_left append_char_to_str "" l ;;
let evens (max : int) : int list = let f (n: int) : (int * int) = ( (n * 2), (n + 1) ) in let stop (n: int) : bool = n * 2 >= max in unfold f stop 0;;
let fib (max : int) : int list = let rec fib_aux n a b = match n with | 0 -> a | 1 -> b | _ -> fib_aux (n-1) b (a+b) in let fib_tl n = fib_aux n 1 1 in let stop (n: int) : bool = fib_tl n >= max in let f (n: int) : (int * int) = ( (fib_tl n), (n + 1) ) in unfold f stop 0;;
let pascal (max : int) : int list list = let stop (row: int list) : bool = List.length row > max in let f (prev_row: int list): (int list * int list) = let l1 = 0 :: prev_row in let l2 = prev_row @ [0] in let row = List.map2 (+) l1 l2 in (prev_row, row) in unfold f stop [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ingredients (Cupcake (_, _, _, l)) = l in let doesnt_have_allergen (a: ingredient) (c) : bool = not (List.exists (fun i -> i = a) (ingredients c)) in let is_allergen_free (c): bool = List.for_all (fun a -> doesnt_have_allergen a c) (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 seed -> (seed, seed + 2)) (fun seed -> seed >= 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 row -> (row, List.map2 (+) ([0] @ row) (row @ [0]))) (fun row -> (List.length row) > max) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (_, _, _, ingredients)) -> List.for_all (fun ingredient -> not (List.exists (fun allergen -> allergen = ingredient) allergens)) ingredients) 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 append_char (s: string) (c: char) : string = let c_string = Char.escaped c in s ^ c_string in List.fold_left append_char "" l ;;
let evens (max : int) : int list = unfold (fun x -> (x, x + 2)) (fun x -> x >= max) 0 ;;
let fib (max : int) : int list = if max <= 1 then [] else 1 :: (unfold (fun (to_add, acc) -> (acc + to_add, (acc, acc + to_add))) (fun (to_add, acc) -> (acc + to_add) >= max) (0, 1));;
let pascal (max : int) : int list list = let next_row (prev_row: int list) : (int list * int list) = match prev_row with | [] -> ([1], [1]) |x :: xs -> ( 1:: List.map2 (+) prev_row (xs @ [0]), 1:: List.map2 (+) prev_row (xs @ [0])) in let stop (prev_row: int list) = List.length (fst(next_row prev_row)) > max in unfold next_row stop [] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let contains_not (x:ingredient) : bool = List.exists (function (y:ingredient) -> (not (List.mem y allergens) )) [x] in let good_list (l: ingredient list) : bool = (List.for_all contains_not l) in let good_cupcake (cake: cupcake) : bool = let Cupcake (p, w, cal, l ) = cake in good_list l in List.filter good_cupcake cupcakes ;;
let string_explode (s : string) : char list = let length = String.length s in let f = String.get s in tabulate f length ;;
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 = let seeder = fun x -> (x, x+2) in let stop = fun y -> y >= max in unfold seeder stop 0 ;;
let fib (max : int) : int list = let seeder = fun x -> let next_el = snd(x) in let next_seed = (snd(x), fst(x) + snd(x)) in (next_el, next_seed) in let stop = fun y -> snd(y) >= max in unfold seeder stop (0, 1) ;;
let pascal (max : int) : int list list = let seeder = fun x -> let list1 = List.tl x in let list2 = List.rev list1 in let list_addition = List.map2 (+) list1 list2 in let temp1 = List.append [1] list_addition in let temp2 = List.rev temp1 in let output = List.append [1] temp2 in (x, output) in let stop = fun y -> List.length y > max in unfold seeder stop [1]; ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check0 (j: ingredient) (a: ingredient) = (j = a) in let check1 (i: ingredient) = not (List.exists (check0 i) allergens) in let check2 (c: cupcake) = match c with | Cupcake (_, _, _, x) -> List.for_all check1 x in List.filter check2 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)) (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 = List.filter (function Cupcake(_,_,_,ingdt_list) -> List.for_all (fun ingdt -> not (List.exists ( fun aller -> aller = ingdt ) allergens)) ingdt_list) cupcakes ;;
let string_explode (s : string) : char list = let ls = tabulate (fun x -> x) (String.length s) in List.map (String.get s) ls;;
let string_implode (l : char list) : string = let ls = List.map (Char.escaped) l in List.fold_left (fun acc str -> acc^str) "" ls;;
let evens (max : int) : int list = unfold (fun x -> (x, x+2)) (fun y -> max <= y) 0;;
let fib (max : int) : int list = unfold (fun (c,x) -> (x, (x,x+c))) (fun (y,z) -> max <= z) (0,1);;
let pascal (max : int) : int list list = unfold (fun acc -> (acc, List.map2 (+) (0::acc) (List.rev (0::acc)))) (fun acc -> List.length acc > max) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let g = fun ing -> not (List.for_all ((!=) ing) allergens) in let f = fun (Cupcake (_,_,_,p)) -> not (List.exists g p) in List.filter (f) cupcakes;;
let string_explode (s : string) : char list = let helper = String.get s in tabulate helper (String.length s);;
let string_implode (l : char list) : string = let helper (n : string) (c : char) = n ^ (Char.escaped c) in List.fold_left helper "" l;;
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max) 0;;
let fib (max : int) : int list = let helper seed = if seed = (0, 0) then (1,(0, 1)) else let ele = (fst seed)+(snd seed) in (ele, (snd seed , ele)) in let condition seed = max <= (fst seed)+(snd seed) || max < 2 in unfold helper condition (0, 0);;
let pascal (max : int) : int list list = let helper seed = if seed = [] then ([1], [1]) else let head = seed @ [0] in let tail = 0 :: seed in let row = List.map2 (+) head tail in (row, row) in unfold helper (fun b -> (List.length b) >= max) [];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let noAllergens ingred = let ans = List.exists (fun b -> b = ingred) allergens in not ans in let safe ccake = let Cupcake (_,_,_,ingredients) = ccake in List.for_all noAllergens ingredients in List.filter safe 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 c -> acc ^ (Char.escaped c)) "" l;;
let evens (max : int) : int list = unfold (fun b -> (b, b + 2)) ((<=) max) 0;;
let fib (max : int) : int list = match max with | 0 | 1 -> [] | _ -> let tmp_list = unfold (fun (a, b) -> ((a, b), (b, a + b))) (fun (a, b) -> max <= b) (1, 1) in List.append [1] (List.map snd tmp_list) ;;
let pascal (max : int) : int list list = match max with | 0 -> [] | _ -> let getNextList l = List.map2 (+) (List.append [0] l) (List.append l [0]) in unfold (fun b -> (b, getNextList b)) (fun b -> max < List.length b) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ingredients cake = let Cupcake (_,_,_,ingredientList) = cake in ingredientList in List.filter (fun c -> (List.for_all (fun a -> not (List.exists (fun i -> i = a) (ingredients c)) ) 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 (fun acc c -> acc ^ (Char.escaped c)) "" l;;
let evens (max : int) : int list = unfold (fun b -> (b, b + 2)) ((<=) max) 0;;
let fib (max : int) : int list = match max with | 0 | 1 -> [] | _ -> let tmp_list = unfold (fun (a, b) -> ((a, b), (b, a + b))) (fun (a, b) -> max <= b) (1, 1) in List.append [1] (List.map snd tmp_list) ;;
let pascal (max : int) : int list list = match max with | 0 -> [] | _ -> let getNextList l = List.map2 (+) (List.append [0] l) (List.append l [0]) in unfold (fun b -> (b, getNextList b)) (fun b -> max < List.length b) [1] ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ingredients cake = let Cupcake (_,_,_,ingredientList) = cake in ingredientList in List.filter (fun c -> (List.for_all (fun a -> not (List.exists (fun i -> i = a) (ingredients c)) ) allergens) ) 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 x -> (x*2, x+1)) (fun x -> x*2 >= max) 0;;
let fib (max : int) : int list = match max with | 0 | 1 -> [] | _ -> 1 :: unfold (fun (x,y) -> (x+y, (y,x+y))) (fun (x,y) -> (x+y) >= max) (0 ,1);;
let pascal (max : int) : int list list = let a l = List.rev (List.tl (List.rev l)) in let b l = List.tl l in match max with | 0 -> [] | 1 -> [[1]] | 2 -> [[1];[1;1]] | _ -> [1] :: [1;1]:: unfold (fun x -> (1 :: List.map2 (+) (a x) (b x) @ [1], 1 :: List.map2 (+) (a x) (b x) @ [1])) (fun x -> List.length x >= max) [1;1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ing = function Cupcake (_,_,_,d) -> d in let xx l p = List.exists(fun x -> not (List.for_all (fun y -> not (y=x)) l)) (ing p) in List.filter (fun x -> not(xx allergens x)) cupcakes ;;
let string_explode (s : string) : char list = tabulate (String.get s)(String.length s);;
let string_implode (l : char list) : string = let x = (List.map (String.make 1) l) in String.concat "" x;;
let evens (max : int) : int list = unfold (fun seed -> (seed, seed+2))(fun limit -> (<=) max limit)(0);;
let fib (max : int) : int list = let rec fib_aux n a b = if n <= 1 then b else fib_aux (n-1) b (a + b) in let rec unfold (f : 'seed -> 'a * 'seed) (stop : 'seed -> bool) (b : 'seed) : 'a list = if stop (fib_aux b 0 1) then [] else let (x, b') = f b in x :: unfold f stop b' in unfold (fun seed-> ((fib_aux seed 0 1), seed +1)) (fun limit -> (<=) max limit) (1);;
let pascal (max : int) : int list list = let rec pas (nth: int) (last_row: int list) : int list = if nth = 0 then last_row else if nth=1 then [1;1] else let past = pas (nth-1) (last_row) in let added = [0;1] @ (List.filter (fun x -> x != 1) past) in (List.map2 (+) past added) @ [1] in unfold (fun seed-> ((pas (seed) ([1])), seed +1))(fun limit -> (<=) max limit)(0);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list): cupcake list = let get_ingredients cupcake: ingredient list = let Cupcake (_,_,_,contain) = cupcake in contain in if (allergens = []) then cupcakes else let rec organize new_cakes allergens= match allergens with |[] -> new_cakes |x :: xs -> if (List.exists (fun a-> new_cakes !=[]) new_cakes) then organize (List.filter (fun a -> (List.for_all (fun a->a != x)(get_ingredients a))) new_cakes) xs else organize new_cakes xs in organize cupcakes allergens;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;