text
stringlengths 0
601k
|
---|
let string_explode (s : string) : char list = let length = String.length s in tabulate (String.get s) length;; let rec fold_right f q l b = match l with | [] -> b | h::t -> f (q h) (fold_right f q t b);; |
let string_implode (l : char list) : string = fold_right (^) Char.escaped 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 (x,y) -> (x,(y,x+y))) (fun (x,y)-> max <= x) (1,1);; |
let pascal (max : int) : int list list = unfold (fun l1 -> (l1,(List.map2 (+) (l1@[0]) ([0]@l1)))) (fun l1 -> max < List.length l1) ([1]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) = List.filter (function Cupcake (_,_,_,ingredients ) -> List.for_all (fun ingred -> not (List.exists (fun allerg -> allerg = ingred) allergens)) ingredients) 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 = let lnew = List.map Char.escaped l in String.concat "" lnew;; |
let evens (max : int) : int list = let f seed = (seed, seed+2) in let stop seed = (seed > max-1) in unfold f stop 0;; |
let fib (max : int) : int list = let f (seed1, seed2) = (seed2, (seed2, seed1 + seed2)) in let stop (seed1, seed2) = (seed2 > max-1) in unfold f stop (0,1);; |
let pascal (max : int) : int list list = let f seed = (seed, (List.map2 (+) (seed @ [0]) (0 :: seed))) in let stop seed = (List.length seed > max) in unfold f stop [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if allergens = [] then cupcakes else let ingredients_of_cupcake (Cupcake (_, _, _, ingredients)) = ingredients in let f ingredient = not (List.exists (fun allergen -> allergen = ingredient) allergens) in let not_allergic cupcake = List.for_all (f) (ingredients_of_cupcake cupcake) in List.filter not_allergic cupcakes;; |
let string_explode (s : string) : char list = tabulate (fun cr -> String.get s cr) (String.length s);; |
let string_implode (l : char list) : string = List.fold_left (fun a b -> a ^ String.make 1 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,b) -> max <= a) (1,1);; |
let pascal (max : int) : int list list = let psclr la = let rec plus list = match list with |[] -> [] |x::xs -> match xs with |[] -> [] |xx::xxs -> (x+xx)::plus(xx::xxs) in la, (plus ([0]@la@[0])) in unfold psclr (fun x -> List.length x > (max)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,z) -> List.for_all (fun x -> (not(List.mem x allergens)) ) z) cupcakes;; |
let string_explode (s : string) : char list = tabulate (fun cr -> String.get s cr) (String.length s);; |
let string_implode (l : char list) : string = List.fold_left (fun a b -> a ^ String.make 1 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,b) -> max <= a) (1,1);; |
let pascal (max : int) : int list list = let psclr la = let rec plus list = match list with |[] -> [] |x::xs -> match xs with |[] -> [] |xx::xxs -> (x+xx)::plus(xx::xxs) in la, (plus ([0]@la@[0])) in unfold psclr (fun x -> List.length x > (max)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,z) -> List.for_all (fun x -> (not(List.exists((==)x) allergens )) ) z) cupcakes;; |
let string_explode (s : string) : char list = let aux = fun x -> String.get s x in tabulate aux (String.length s) ;; |
let string_implode (l : char list) : string = let s_list = List.map (Char.escaped) l in String.concat "" 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 = unfold (fun (a , b) -> let new_a = a + b and new_b = a in (a+b, (new_a, new_b))) (fun (a , b) -> max <= a + b) (0 , 1);; |
let pascal (max : int) : int list list = unfold (fun (d, l1) -> ( l1, ( (d+1) , List.map2 (+) ([0] @ l1) (l1 @ [0]) ) )) (fun (d, l1) -> max <= d) (0, [1]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_one_cupcake c = fun a -> let looking_for x = x == a in not (List.exists looking_for (get_ingredients c)) in let feed_allergens allergens = fun c -> List.for_all (check_one_cupcake c) allergens in List.filter (feed_allergens 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)) (fun b -> if max mod 2 = 0 then max < b + 2 else max < b) 0;; |
let fib (max : int) : int list = unfold (fun b -> let (x,y) = b in (x, (y,x+y))) (fun a -> let (x,y) = a in max <= x) (1,1);; let next_row (prev_r : int list) : int list = if List.length prev_r = 1 then [1;1] else let l = 1::(List.filter (fun a -> a != 1) prev_r) in 1::(List.map2 (+) l (List.rev l))@[1] ;; |
let pascal (max : int) : int list list = unfold (fun b ->(b,next_row b)) (fun b -> max < List.length b) [1];; let stop b = match b with |([],_) |(_,[]) -> true |(_,_) -> false ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if allergens = [] then cupcakes else List.filter (fun c -> let Cupcake(_,_,_, ingr) = c in List.for_all (fun ing -> not(List.exists ((=) ing ) allergens)) ingr) cupcakes ;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = (List.map Char.escaped l |> 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 (c,_) -> max <= c ) (1, 1);; |
let pascal (max : int) : int list list = if max = 0 then [] else 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(_,_,_,ingredient) -> List.for_all (function x -> not(List.exists ((=) x) allergens)) ingredient) 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 to_string = Char.escaped in let result = List.map to_string l in List.fold_left (^) "" result;; |
let evens (max : int) : int list = unfold (fun num -> num, num +2) (fun x-> (x>=max) ) 0;; |
let fib (max : int) : int list = let check_limit l= match l with |[]->false |x::_->(x>=max) in unfold (fun [x;y]-> x, [y;(x+y)]) check_limit [1;1] let triangle row= let next_row row = List.map2 (+) (0:: row)(row@[0]) in let rec loop row' = if row'=[] then [] else (row';(loop (next_row row')))in row,loop (next_row row);; |
let pascal (max : int) : int list list = unfold triangle (fun f ->List.length f > max) [1] let convert_tuple = fun (l1,l2) -> let (x::xs,y::ys) = (l1, l2) in ((x, y), (xs, ys)) let len =fun (l1, l2) -> List.length l1 == 0 || List.length l2 == 0;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let gredient_list (Cupcake(_,_,_,l)) = l in let check_Nuts c= List.exists (fun x-> x=Nuts) (gredient_list c) in let check_Gluten c = List.exists(fun x->x= Gluten) (gredient_list c) in let check_Soy c= List.exists(fun x->x= Soy) (gredient_list c) in let check_Dairy c= List.exists(fun x->x= Dairy) (gredient_list c) in let f ingredient c = match ingredient with |Nuts->check_Nuts c |Gluten->check_Gluten c |Dairy->check_Dairy c |Soy->check_Soy c in let rec check_aller cupcake_list = match cupcake_list with |[]->[] |x::xs-> if List.exists (fun x-> x=Nuts) allergens && f Nuts x then let allergens = List.filter (fun x-> x=Nuts) allergens in let cupcake_list= xs in check_aller cupcake_list else if List.exists (fun x-> x=Gluten) allergens && f Gluten x then let allergens = List.filter (fun x-> x=Gluten) allergens in let cupcake_list= xs in check_aller cupcake_list else if List.exists (fun x-> x=Soy) allergens && f Soy x then let allergens = List.filter (fun x-> x=Soy) allergens in let cupcake_list= xs in check_aller cupcake_list else if List.exists (fun x-> x=Dairy) allergens && f Dairy x then let allergens = List.filter (fun x-> x=Dairy) allergens in let cupcake_list= xs in check_aller cupcake_list else cupcake_list in if List.length cupcakes =1 && List.for_all (fun x -> gredient_list x=[]) cupcakes then cupcakes else check_aller 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)) (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 (+) (List.append [0] b) (List.append b [0]))])) (fun [b] -> max < List.length b) [[1]];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter(fun (Cupcake (_, _, _, a)) -> List.for_all (fun b -> not (List.exists (fun c -> c = b) allergens)) a) 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)) (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 (+) (List.append [0] b) (List.append b [0]))])) (fun [b] -> max < List.length b) [[1]];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter(fun (Cupcake (_, _, _, a)) -> List.for_all (fun b -> not (List.exists (fun c -> c = b) allergens)) a) cupcakes ;; |
let string_explode (s : string) : char list = let my_f n = n in let li =tabulate my_f (String.length s) in let second_f mystr i= mystr.[i] in List.map (second_f s) li;; |
let string_implode (l : char list) : string = let f (my_char: char) (s:string) : string= let templ = ["";s] in String.concat (Char.escaped my_char) templ in List.fold_right f l "";; |
let evens (max : int) : int list = let next_even n= (n,n+2) in unfold next_even (fun b -> max <= b) 0;; |
let fib (max : int) : int list = let next_fib (n1,n2)= (n1,(n2,n1+n2)) in unfold next_fib (fun (b,c) -> max <= b) (1,1);; |
let pascal (max : int) : int list list = let removeFirst list= match list with | [] -> [] | x :: xs -> xs in let removeLast li= match li with | [] -> [] | _-> match List.rev li with |x::xs -> List.rev xs |[] -> [] in let next_row myList= let l1 = removeFirst myList in let l2 = removeLast myList in let new_list = List.map2 (+) l1 l2 in (myList, [1] @ new_list @ [1]) in unfold next_row (fun li -> max < List.length li) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ingListnotcontainall (an_ing: ingredient) = not (List.exists (fun b -> b = an_ing) allergens ) in let check_ing_li (ing_li : ingredient list) : bool = List.for_all ingListnotcontainall ing_li in let cupcake_checker acupcake : bool = let Cupcake (a,b,c,li) = acupcake in check_ing_li li in List.filter cupcake_checker 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 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) -> max <= a) (1, 1);; |
let pascal (max : int) : int list list = unfold (fun x -> (x, List.map2 (+) ([0] @ x) (x @ [0]))) (fun x -> max < List.length x) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (price, weight, calories, ingredient)) -> List.for_all (fun ingr -> not (List.exists (fun alg -> alg = ingr) allergens)) ingredient) 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_right (fun chr s -> Char.escaped chr ^ s) l "";; |
let evens (max : int) : int list = unfold (fun n -> (2 * n, n + 1)) (fun n -> max <= (2 * n)) 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 f (n, hd, tl) = let md = List.map2 (+) hd tl in let hd' = 1 :: md in let tl' = List.append md [1] in let res = 1 :: tl in (res, (n + 1, hd', tl')) in unfold f (fun (n, _, _) -> max < n) (1, [], []);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_gredient_af g = not (List.exists (fun x -> x = g) allergens) in let is_allergy_free (Cupcake (_, _, _, gs)) = List.for_all is_gredient_af gs in List.filter is_allergy_free 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_right (fun chr -> (^) (Char.escaped chr)) l "";; |
let evens (max : int) : int list = unfold (fun n -> (2 * n, n + 1)) (fun n -> max <= (2 * n)) 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 f (n, hd, tl) = let md = List.map2 (+) hd tl in let hd' = 1 :: md in let tl' = List.append md [1] in let res = 1 :: tl in (res, (n + 1, hd', tl')) in unfold f (fun (n, _, _) -> max < n) (1, [], []);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_gredient_af g = not (List.exists (fun x -> x = g) allergens) in let is_allergy_free (Cupcake (_, _, _, gs)) = List.for_all is_gredient_af gs in List.filter is_allergy_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)) (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, (1 :: (List.map2 (+) (List.rev (List.tl b)) (List.tl b))) @ [1]) ) (fun b -> max < List.length b) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (p, w, c, id)) -> List.for_all (fun i -> (not (List.exists (fun alg -> i == alg) allergens))) id) cupcakes;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = let mappedList = List.map (Char.escaped) l in String.concat ("") (mappedList);; |
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, b + a))) (fun (a,b) -> max <= a) (1,1);; |
let pascal (max : int) : int list list = unfold (fun (a,n) -> (a, (List.map2 (+) (a @ [0]) ([0] @ a) , n + 1 ))) (fun (a, n) -> max <= n) ([1], 0);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let isolate_ingredients = function Cupcake(_,_,_,ingr) -> ingr in let check_one_ingredient ( cupcake_ingredient : ingredient ) : bool = not(List.mem ( cupcake_ingredient ) ( allergens )) in let allergen_in_cupcake ( cupcake_ingredients : ingredient list ) : bool = List.exists (check_one_ingredient) ([]) in let no_allergens_in_cupcake (cupcake : cupcake) : bool = List.for_all (check_one_ingredient) (isolate_ingredients(cupcake)) in let clean_cupcake ( cupcake ) = (allergen_in_cupcake (isolate_ingredients(cupcake)) || no_allergens_in_cupcake (cupcake)) in List.filter (clean_cupcake) (cupcakes);; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
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 = let is_done = fun x -> x >= max in let next = fun (a: int) -> (a, a+2) in unfold next is_done 0 ;; |
let fib (max : int) : int list = let is_done = fun ((x, y) : int * int) -> y >= max in let next = fun ((x, y) : int * int) -> (y, (y, y + x)) in unfold next is_done (0, 1) ;; let next_pascal (l: int list) : int list * int list = match l with | [] -> ([1], [1]) | [1] -> ([1; 1], [1; 2; 1]) | _ -> let l1 = List.tl l in let l2 = List.rev l1 in let l3 = List.map2 (+) l1 l2 in let l4 = List.append l3 [1] in let l5 = List.append (List.rev l4) [1] in (l, l5) ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.