text
stringlengths 0
601k
|
---|
let pascal (max : int) : int list list = let getNextRow (x: int list) = List.map2 (+) (List.append [0] x) (List.append x [0]) in unfold(fun b -> (b, (getNextRow b))) (fun b -> max < (List.length b)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let containsAllergen (c: cupcake) : bool = let inAllergens ingredient : bool = not(List.exists (fun a -> a = ingredient) allergens ) in let Cupcake (_, _, _, ingreds) = c in List.for_all inAllergens ingreds in List.filter containsAllergen 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) -> (b, (b, a+b))) (fun (_,b) -> max <= b) (0,1) ;; |
let pascal (max : int) : int list list = unfold (fun b -> (b, 1 :: (List.map2 (+) b (List.tl b@[0])))) (fun b -> max < List.length b) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let not_allergen (e : ingredient) : bool = not (List.exists (fun a -> a = e) allergens) in let is_safe (this_cupcake : cupcake) : bool = let Cupcake (_,_,_, contents) = this_cupcake in List.for_all not_allergen contents in List.filter is_safe 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 = let new_list = List.map Char.escaped l in String.concat "" new_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 removeHead (l: 'a list) : 'a list = match l with |[] -> failwith "List is empty" |x::xs -> xs ;; |
let pascal (max : int) : int list list = let new_list l = let l1 = 0::l in let l2 = List.rev l1 in List.map2 (+) l1 l2 in unfold (fun b -> (b,new_list b)) (fun b -> max <= (List.length b) - 1) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_safe a :bool = not (List.exists ((=) a) allergens) in let is_safe_for_all a_list = List.for_all is_safe a_list in List.filter (fun (Cupcake (p, w, c, is)) -> is_safe_for_all is) cupcakes;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = let newlist = List.map Char.escaped l in List.fold_left (^) "" newlist;; |
let evens (max : int) : int list = let nats max = unfold (fun b -> (b, b+1)) (fun b -> max <= b) 0 in List.filter (fun x -> x mod 2 =0) (nats max);; |
let fib (max : int) : int list = let thelist = unfold (fun (a, b) -> (a, (b, a+b))) (fun (a, b) -> a > max) (1, 1) in List.filter(fun x -> x !=max) thelist;; |
let pascal (max : int) : int list list = let next_row row = List.map2 (+) (0 :: row) (row @ [0]) in let loop = unfold (fun (a, b) -> (a, (b, a+b))) (fun (a, b) -> a <= max) (1, 1) in let thelist = List.filter(fun x -> x !=max) loop in;; |
let pascal n = let rec loop i row = if i = n then [] else row :: loop (i+1) (next_row row) in loop 0 [1] in pascal max ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let checkall allergens cupcakes= let rec check allergens bool = if bool then true else match allergens with | [] -> bool | (h::t) -> check t (List.exists (fun x -> x = h) cupcakes ) in check allergens false in let nestedlist cupcakes = let get_ingredient acup= let Cupcake (_,_,_,q) = acup in q in let rec newlist cupcakes acc = match cupcakes with | []-> acc | (h::t) -> newlist t ((get_ingredient h) :: acc) in newlist cupcakes [] in let reverse list= let rec support acc = function | [] -> acc | hd :: tl -> support (hd :: acc) tl in support [] list in let reversednewlist = reverse (nestedlist cupcakes) in let inlist = List.filter (fun x -> not (checkall allergens x)) (reversednewlist) in let listfor = List.for_all (checkall allergens) inlist in let get_ingredient acup= match acup with | Cupcake (_,_,_,q) -> q | Cupcake (_,_,b,_)->[] in let abool = listfor in let final2 ingrelist finalele = let rec finalcheck ingrelist finalele bool = if bool then true else match ingrelist with | [] -> false | x :: xs -> if x = get_ingredient finalele then true else finalcheck xs finalele bool in finalcheck ingrelist finalele false in List.filter (final2 inlist) 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 = let f s = s,s+2 in let stop s = s >= max in unfold f stop 0;; |
let fib (max : int) : int list = let f (s1,s2) = (s1 , (s2, s2+s1)) in let stop (s1,s2) = (s1 >= max) in unfold f stop (1,1);; |
let pascal (max : int) : int list list = let f s = s, List.map2 (+) (List.append [0] s) ( List.append s [0]) in let stop s = (List.length s) > max in unfold f stop [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( function Cupcake (_,_,_,i) -> List.for_all ( function i -> not (List.exists ((=) i) allergens)) i) 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 Char.escaped l in String.concat "" x;; |
let evens (max : int) : int list = if max < 0 then failwith "Integer must be larger than 0" else let f (l : 'seed) : 'a * 'seed = (l * 2, l + 1) in let stop (k : 'seed) : bool = k * 2 >= max in unfold f stop 0 let rec fib_helper (n : int) : int = match n with | 0 -> 1 | 1 -> 1 | _ -> fib_helper (n - 2) + fib_helper (n - 1);; |
let fib (max : int) : int list = if max < 0 then failwith "Integer must be larger than 0" else let f (l : 'seed) : 'a * 'seed = (fib_helper l, l+1) in let stop (k : 'seed) : bool = fib_helper k >= max in unfold f stop 0 let rec get_pascal_number (x : int) (y: int) : int = if y = 0 || y = x then 1 else get_pascal_number(x-1) (y-1) + get_pascal_number(x-1) y let rec make_row (x : int) (y: int) : int list = match y with | -1 -> [] | _ -> get_pascal_number x y :: make_row x (y - 1);; |
let pascal (max : int) : int list list = if max < 0 then failwith "Integer must be larger than 0" else let f (l : 'seed) : 'a * 'seed = (make_row l l, l+1) in let stop (k : 'seed) : bool = k + 1 > max in unfold f stop 0;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let filter_check (c : cupcake) = let Cupcake (_,_,_,ingredients) = c in List.for_all (function allergen -> not (List.exists ((=) allergen) ingredients)) allergens in List.filter (filter_check) cupcakes;; |
let string_explode (s : string) : char list = let fn i = String.get s i in tabulate fn (String.length s);; |
let string_implode (l : char list) : string = let lp = List.map Char.escaped l in List.fold_left (^) "" lp;; |
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,n) -> (b, (b,a+b,n+1))) (fun (a,b,n)-> max <= b) (0,1,0);; |
let pascal (max : int) : int list list = let n2 p = List.map2 (+) (p@[0]) ([0]@p) in unfold (fun (ln) -> (ln, n2 ln) ) (fun (l) -> max < List.length l) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake(pr, w, c,iL):cupcake) -> List.for_all (fun i -> not (List.exists (fun g -> i=g) iL)) allergens) cupcakes;; |
let string_explode (s : string) : char list = let index_to_char (n:int) = String.get s n in tabulate index_to_char (String.length s) ;; |
let string_implode (l : char list) : string = let rec stringL_to_string stringL : string = match stringL with | [] -> "" | h :: t -> h ^ (stringL_to_string t) in stringL_to_string (List.map 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 = if max <= 1 then [] else if max = 2 then [1;1] else let count = ref 1 in let fibHelper n = let result = !count + n in count := n; result in [1] @ unfold (fun x -> (x,fibHelper x)) (fun x -> max <= x) 1 ;; |
let pascal (max : int) : int list list = let rec removeLast = function | [] -> [] | [x] -> [] | h :: t -> h :: removeLast t in let operation l = [0] @ removeLast l in unfold (fun x -> (x, (List.map2 (+) x (operation x)) @ [1])) (fun x -> List.length x > max ) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec checkAllergy all cup = match all with | [] -> false | h :: t -> if List.mem h cup = true then true else checkAllergy t cup in let check cup = let Cupcake (_,_,_,iList) = cup in not (checkAllergy allergens iList) in let flag = List.exists check cupcakes in let flag = List.for_all check cupcakes 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 = List.fold_left (^) "" (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 = let f = fun previous -> (previous, previous) in let stop = fun current -> current = max in unfold f stop 0;; |
let pascal (max : int) : int list list = let f = fun previous -> (previous, (let x = List.append previous [0] in let y = List.append [0] previous in List.map2 (+) x y )) in let stop = fun previous -> List.length previous > max in unfold f stop [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;; |
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 = let l = List.map Char.escaped l in List.fold_left (^) "" l;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ( (<=) max ) 0;; |
let fib (max : int) : int list = let f = fun (b0, b1) -> ((b0, b1), (b1, b0 + b1)) in let l = unfold f (fun (b0, b1) -> max <= b0) (1, 1) in List.map (fun (b0, b1) -> b0) l;; |
let pascal (max : int) : int list list = let f = fun l -> (l, List.map2 (+) (List.append [0] l) (List.append l [0])) in unfold f (fun l -> max < (List.length l)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let f = fun (Cupcake (_, _, _, l): cupcake) -> List.for_all (fun x -> not (List.exists ( (=) x ) allergens) ) l in List.filter f cupcakes;; |
let string_explode (s : string) : char list = tabulate (String.get (s)) (String.length s) ;; |
let string_implode (l : char list) : string = let l1 = List.map (fun a -> Char.escaped a) l in List.fold_left (^) "" l1 ;; |
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 next_row row = List.map2 (+) ([1] @ row) (row @ [1]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let difference l1 l2 = List.filter (fun x -> not (List.mem x l2)) l1 in List.filter (function Cupcake(_,_,_,allergen) -> List.for_all (fun a -> List.exists ((=) a) (difference allergens allergen)) allergens ) 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 (String.make 1) (l));; |
let evens (max : int) : int list = match max with | 0 -> [] | _ -> if (max mod 2 = 0) then List.rev (unfold (fun max -> (max, max - 2)) (fun stop -> match stop with | -2 -> true | _ -> false) (max-2)) else let max = max - 1 in List.rev (unfold (fun max -> (max, max - 2)) (fun stop -> match stop with | -2 -> true | _ -> false) max);; |
let fib (max : int) : int list = match max with | 0 -> [] | 1 -> [] | _ -> List.append [1; 1] (unfold (fun v -> (v, let w = float_of_int(v) in (int_of_float((w *. 840017. /. 500000.))))) (fun v -> v >= max) 2) let list = [1];; |
let pascal (max : int) : int list list = match max with | 0 -> [] | 1 -> [[1]] | _ -> [1] :: (unfold (fun list -> ([1] @ (List.map2 (+) (List.tl list) (List.tl list |> List.rev)) @ [1], [1] @ (List.map2 (+) (List.tl list) (List.tl list |> List.rev)) @ [1])) (fun list -> (List.length ([1] @ (List.map2 (+) (List.tl list) (List.tl list |> List.rev)) @ [1])) > max) [1]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) = List.filter (let amAllergicIngredients (cupCakeIngredients : ingredient list) (allergen : ingredient) : bool = not (List.for_all (amAllergicNotMatch allergen) cupCakeIngredients) in let amAllergicCupcake (allergens : ingredient list) (cupCake : cupcake) : bool = not (List.exists (amAllergicIngredients (getIngredients cupCake)) allergens) in amAllergicCupcake allergens) cupcakes;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = let l1 = List.map Char.escaped l in List.fold_left (^) "" l1;; |
let evens (max : int) : int list = unfold (fun b -> (b*2,b+1)) (fun b -> max<=b*2) 0 ;; |
let fib (max : int) : int list = let fib_tl n = let rec fib_aux n a b = if n == 0 then 1 else if n == 1 then a+b else let w = n-1 in let v = a+b in fib_aux w b v in fib_aux n 0 1 in unfold (fun b -> (fib_tl (b),b+1)) (fun b -> max<=fib_tl (b)) 0 ;; |
let pascal (max : int) : int list list = let f1 l1 = let a = List.tl l1 in let b = List.rev a in let c = List.map2 (+) a b in (l1,[1] @ c @ [1]) in let f2 l2 = max < List.length l2 in unfold f1 f2 [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let f0 = function Cupcake (_,_,_,ingred_lst) -> ingred_lst in let f3 = (==) in let f1 ingred = not (List.exists (f3 ingred) allergens) in let f2 cupcake = List.for_all f1 (f0 cupcake) in List.filter f2 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 (a: string) (b: char) = a ^ (Char.escaped b) in List.fold_left f "" l ;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> b >= 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 = raise NotImplemented ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented ;; |
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 (a: string) (b: char) = a ^ (Char.escaped b) in List.fold_left f "" l ;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> b >= 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 = raise NotImplemented ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ingred_lst = function Cupcake (_,_,_,ingred_lst) -> ingred_lst in let afings ingredient = not (List.exists (fun allergen -> allergen == ingredient) allergens) in let afc cupcake = List.for_all afings (get_ingred_lst cupcake) in List.filter afc 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 str ch -> str ^ (Char.escaped ch) ) "" l ;; |
let evens (max : int) : int list = unfold (function seed -> (seed, seed + 2)) (function seed -> seed >= max) 0 ;; |
let fib (max : int) : int list = unfold (function (a, b) -> (a, (b, a + b))) (function (a, b) -> a >= max) (1, 1) ;; |
let pascal (max : int) : int list list = unfold (function l -> (l, List.map2 (+) (l @ [0]) (0 :: l) ) ) (function l -> List.length l > max) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( function cupcake -> let Cupcake (_, _, _, il) = cupcake in List.for_all ( function allergen -> not (List.exists ( function i -> allergen = i ) il) ) allergens ) cupcakes ;; |
let rec string_explode (s : string) : char list = let get_s = String.get s in tabulate get_s (String.length s) ;; |
let string_implode (l : char list) : string = let str_ls = List.map Char.escaped l in List.fold_left (^) "" str_ls ;; |
let evens (max : int) : int list = let func b = (b, b+2) in let stop = (<=) max in unfold func stop 0 ;; |
let fib (max : int) : int list = if max = 0 then [] else let func (a,b) = (b, (b, a+b)) in let stop (a,b) = max <= b in unfold func stop (0,1) ;; |
let pascal (max : int) : int list list = let func ls = (ls, (List.map2 (+) (0 :: ls) (List.append ls [0]))) in let stop ls = List.length ls > max in unfold func stop [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let has_no_allergens (c : cupcake) = let Cupcake(p, w, c, ingr_ls) = c in let ingr_not_allergen ingr = let allergen_equals_ingr ingr allergen = allergen=ingr in not (List.exists (allergen_equals_ingr ingr) allergens) in List.for_all ingr_not_allergen ingr_ls in List.filter has_no_allergens cupcakes ;; |
let string_explode (s : string) : char list = if(String.length s = 0) then [] else tabulate (String.get s) (String.length s) ;; |
let string_implode (l : char list) : string = if(List.length l = 0) then "" else let list = List.map (Char.escaped) l in List.fold_left (^) ("") list ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.