text
stringlengths 0
601k
|
---|
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 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 (function Cupcake (_,_,_,ingredients) -> List.for_all (fun a -> not (List.exists (fun i -> i = a) ingredients)) allergens) cupcakes ;; |
let string_explode (s : string) : char list = raise NotImplemented;; |
let string_implode (l : char list) : string = raise NotImplemented;; |
let evens (max : int) : int list = raise NotImplemented;; |
let fib (max : int) : int list = raise NotImplemented;; |
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 x=(String.length s) in tabulate (String.get s) x;; |
let string_implode (l : char list) : string = let x=List.map Char.escaped l in String.concat "" x;; |
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 (a,b)-> max<=b) (0,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 (_,_,_,ind_list) -> List.for_all (fun alle -> not (List.exists ((==)alle) ind_list) ) allergens ) cupcakes;; |
let string_explode (s : string) : char list = let x=(String.length s) in tabulate (String.get s) x;; |
let string_implode (l : char list) : string = let x=List.map Char.escaped l in String.concat "" x;; |
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 (a,b)-> max<=b) (0,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 (_,_,_,ind_list) -> List.for_all (fun alle -> not (List.exists ((==)alle) ind_list) ) 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 (a,b) -> (b, (b, a+b))) (fun (a,b) -> max <= b) (0,1) ;; |
let pascal (max : int) : int list list = unfold (fun b -> (b, List.map2 (+) (b @ [0]) (List.rev (b @ [0])))) (fun b -> max < List.length b) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun x -> let Cupcake (_, _, _, list) = x in List.for_all (fun x -> not(List.exists (fun y -> y = x) allergens) ) list ) 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 = let f (x) = (x, x+2) in let stop (s) = (s >= max) in unfold (f) (stop) 0;; |
let fib (max : int) : int list = let f (x, y) = (abs(x+y), (y, abs(x+y))) in let stop (s1, s2) = (abs(s1 + s2) >= max) in unfold f stop (-1, 0);; |
let pascal (max : int) : int list list = let f (row : int list) = (row, (List.map2 (+) (0 :: row) (row @ [0]))) in let stop (row : int list) = (List.length row) > max in unfold f stop [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let f1 i = not(List.exists ((==) i) allergens) in let f2 (Cupcake(_, _, _, l):cupcake) = List.for_all f1 l in List.filter f2 cupcakes;; |
let string_explode (s : string) : char list = let length = String.length s in tabulate (String.get s) length;; |
let string_implode (l : char list) : string = let append_char_to_string acc c = let c = Char.escaped c in acc ^ c in match l with | [] -> "" | _ -> List.fold_left append_char_to_string "" 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 (b1, b2) -> (b1, (b2, (b1 + b2)))) (fun (b1, b2) -> max <= b1) (1,1);; |
let pascal (max : int) : int list list = let get_next_row acc = let list_len = List.length acc in if (list_len = 1) then [1;1] else let l1 = List.tl acc in let l2 = List.rev l1 in let new_list = List.map2 (+) l1 l2 in let new_list = new_list @ [1] in let new_list = List.rev_append new_list [1] in new_list ; in unfold (fun b -> (b, get_next_row b)) (fun b -> max < (List.length b)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec contains_allergens (i_list : ingredient list) : bool = match i_list with | [] -> false | (x::t) -> let contains = List.exists (fun b -> b = x) allergens in if (contains) then true else contains_allergens t in let cupcake_contains (c : cupcake) : bool = match c with | Cupcake (_,_,_,[]) -> false | Cupcake (_,_,_,ilist) -> contains_allergens ilist in let negate_func cupcake = let b = cupcake_contains cupcake in match b with | true -> false | false -> true in if (List.for_all cupcake_contains cupcakes) then [] else List.filter negate_func cupcakes;; |
let string_explode (s : string) : char list = let n = String.length s and f = String.get s in match n with | 0 -> [] | _ -> tabulate f n let cat (s1 : string) (s2 : string) : string = s1 ^ s2;; |
let string_implode (l : char list) : string = let f (c : char) (s : string) : string = cat (Char.escaped c) s in match l with | [] -> "" | _ -> List.fold_right f l "";; |
let evens (max : int) : int list = let f = fun b -> (b, b+2) in unfold f (fun b -> max <= b) 0 let rec f (n : int) : int = match n with | (0|1) -> 1 | _ -> (f (n-2)) + (f (n-1));; |
let fib (max : int) : int list = unfold (fun b -> (f b, b+1)) (fun b -> max <= (f b)) 0 let rec fact (n: int): int = match n with | 0 -> 1 | _ -> n * fact (n - 1) let binomial (n: int) (k: int) = fact n / (fact k * fact (n - k)) let row (length : int) = unfold (fun b -> (binomial (length-1) b, b+1)) (fun b -> length <= b) 0;; |
let pascal (max : int) : int list list = unfold (fun b -> (row b, b+1)) (fun b -> max+1 <= b) 1;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let f (c : cupcake) : bool = let Cupcake (p, w, cal, l) = c in let f1 (i : ingredient) : bool = not (List.exists (fun b -> b=i) l) in List.for_all f1 allergens in List.filter f cupcakes;; |
let string_explode (s : string) : char list = let get_char = String.get s in tabulate get_char (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 x -> (x, x + 2)) (fun x -> x >= max) 0;; |
let fib (max : int) : int list = let next = function | (0, 0) -> (1, (1, 0)) | (a, b) -> (a+b, (a+b, a)) in let compare = function | (0, 0) -> 1 >= max | (a, b) -> a+b >= max in unfold (next) compare (0,0);; |
let pascal (max : int) : int list list = let next = function | [] -> ([1], [1;1]) | l -> let no_tail = List.rev (List.tl (List.rev l )) in let next_list = List.map2 (+) (List.tl l) no_tail in let final_list = 1 :: (next_list @ [1]) in (l, final_list) in let stop l = (List.length l) > max in if max = 0 then [] else unfold (next) stop [];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let filter c = let Cupcake (_,_,_,ingredients) = c in List.for_all (fun i -> not (List.exists (fun a -> a == i) allergens) ) ingredients in List.filter filter 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 = let f (c : char) (str : string) : string = String.concat "" ((String.make 1 c) ::str::[]) in List.fold_right f l "";; |
let evens (max : int) : int list = let stop (num : int) : bool = num >= max in let f (cur : int) : int * int = (cur, cur + 2) in unfold f stop 0 ;; |
let fib (max : int) : int list = if max <= 1 then [] else let stop ((prev, cur) : int * int) : bool = cur >= max in let f ((prev, cur) : int * int) : int * (int * int) = (cur, (cur, cur + prev)) in 1 :: (unfold f stop (1, 1));; |
let pascal (max : int) : int list list = let stop ((n, curRow) : int * int list) : bool = n > max in let f ((n, curRow) : int * int list) : int list * (int * int list) = let l1 = List.tl curRow in let l2 = List.rev (List.tl (List.rev curRow)) in let nextRow = 1 :: (List.append (List.map2 (+) l1 l2) (1 :: [])) in (curRow, (n + 1, nextRow)) in unfold f stop (1, 1::[]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ingredients_not_in_allergens (element : ingredient) : bool = List.exists (fun (allergen : ingredient) -> allergen == element) allergens == false in let allergen_free (cake : cupcake) = let Cupcake(price, weight, calories, ingredients) = cake in List.for_all ingredients_not_in_allergens ingredients in List.filter allergen_free cupcakes;; |
let string_explode (s : string) : char list = let get_char i = String.get s i in tabulate (get_char) (String.length s) ;; |
let string_implode (l : char list) : string = let add_char c s = (Char.escaped c) ^ s in List.fold_right (add_char) l "" ;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0;; |
let fib (max : int) : int list = let breaker x = match x with | (a, b) when a + b >= max -> true | _ -> false in let get_next y = match y with | (1, 0) -> (1, (0, 1)) | (a, b) -> ((a + b), (b, a + b)) in unfold (get_next) (breaker) (1, 0);; |
let pascal (max : int) : int list list = let breaker x = (List.length x) > max in let get_next y = (y, List.map2 (+) ([0] @ y) (y @ [0])) in unfold (get_next) (breaker) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let condition cupcake = let Cupcake (_,_,_,x) = cupcake in List.for_all (fun a -> not (List.exists (fun b -> b = a) allergens)) x in List.filter condition cupcakes ;; |
let string_explode (s : string) : char list = let length = String.length s in tabulate (fun x -> String.get s x) length ;; |
let string_implode (l : char list) : string = let l2 = List.map (fun x -> Char.escaped x) l in String.concat "" l2 ;; |
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) -> x >= 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 = if allergens = [] then cupcakes else let safe (c : cupcake) = let Cupcake (_, _, _, ingredients) = c in List.for_all (fun i -> not (List.exists (fun x -> x = i) ingredients)) allergens in List.filter (fun c -> safe c) 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 let concat = (^) in List.fold_left (concat) "" l1;; |
let evens (max : int) : int list = let stop (x1,x2)= x1>=x2 in let f1 (y1,y2) = (y1,(y1+2,y2)) in unfold f1 stop (0,max);; |
let fib (max : int) : int list = let stop (x1,x2,x3) = x1>=x3 in let f1 (y1,y2,y3) = (y1,(y2,y1+y2,y3)) in unfold f1 stop (1,1,max);; |
let pascal (max : int) : int list list = if max = 0 then [] else if max = 1 then [[1]] else let rec aux input = if input=0 then 1 else 0 in let aux1 = tabulate aux max in let dup1 l1 = (List.tl l1)@[0] in let modi l = List.rev (List.tl (List.rev (1::l))) in let stop (x1,x2,x3,x4) = x3=x4 in let f1 (y1,y2,y3,y4) = let next_row = List.map2 (+) y1 (dup1 y1) in let f2 e = e!=0 in ((List.filter f2 y1),(modi next_row,modi (dup1 next_row),y3+1,y4)) in (unfold f1 stop (aux1,dup1 aux1,0,max));; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let find ai bj = ai = bj in let find_set_b set_b ai = (List.exists (find ai) set_b)=false in let find_all_a set_a set_b= List.for_all (find_set_b set_b) set_a in let find_ingredient c1 = let Cupcake (_,_,_,x) = c1 in find_all_a allergens x in List.filter (find_ingredient) cupcakes;; |
let string_explode (s : string) : char list = let s_length = String.length s in let g = String.get s in tabulate g s_length ;; |
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) -> (a, (b, a + b))) (fun (a,b) -> (max <= a)) (1,1) ;; let rec fact (n: int): int = match n with | 0 -> 1 | _ -> n * fact(n - 1) ;; let binomial (n: int) (k: int) = if n < 0 then domain () else (if k = n then 1 else fact n / (fact k * fact (n - k))) ;; |
let pascal (max : int) : int list list = let row (n: int) = unfold (fun k -> ((binomial (n-1) k), k + 1)) (fun k -> n-1 < k) 0 in unfold (fun b -> (row b, b + 1)) (fun b -> max < b) 1 ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let get_ings = function Cupcake (_, _, _, ing_l) -> ing_l in let same_ing (ing1: ingredient) (ing2: ingredient) = ing1 == ing2 in let safe_ing (ing: ingredient) = not (List.exists (same_ing ing) allergens) in let safe (cc: cupcake) = List.for_all safe_ing (get_ings cc) 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 = let concat_char = fun (a: char) (b: string) -> Char.escaped a ^ b in List.fold_right concat_char l "" ;; |
let evens (max : int) : int list = let f x = (x * 2, x + 1) in let stop x = x * 2 >= max in unfold f stop (0) ;; let e = evens (-1);; |
let fib (max : int) : int list = let stop (_, b) = b >= max in let f (a, b) = (b, (b, a + b)) in unfold f stop (0, 1) ;; |
let pascal (max : int) : int list list = let stop level = List.length level > max in let f level = let list_1 = [0] @ level in let list_2 = level @ [0] in let next_level = List.map2 (+) list_1 list_2 in (level, next_level) in unfold f stop [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let negate predicate = fun arg -> not (predicate arg) in let allergen_free (cp: cupcake) : bool = let Cupcake (_, _, _, ingrs) = cp in List.for_all (negate (fun a -> List.exists (fun ing -> ing == a) ingrs)) allergens in List.filter allergen_free cupcakes ;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = let hold = List.map Char.escaped l in List.fold_left (^) "" hold;; |
let evens (max : int) : int list = unfold (function x -> (x, x+2)) (function x -> x >= max) 0;; |
let fib (max : int) : int list = let ls = unfold (fun (a, b) -> ( (a, b), (b, a+b) ) ) (fun (a,b) -> max <= b) (0, 1) in snd(List.split ls);; |
let pascal (max : int) : int list list = let get_next_row l : int list = List.map2 (+) (List.append [0] l) (List.append l [0]) in unfold (fun ls -> (ls, get_next_row ls ) ) (fun ls -> max+1 <= List.length ls) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,ingre) -> List.for_all (function i -> not( List.exists (function x -> i == x) ingre ) ) allergens ) cupcakes;; |
let string_explode (s : string) : char list = if String.length s = 0 then [] else let f i = (String.get s i) in tabulate f (String.length s);; |
let string_implode (l : char list) : string = match l with | [] -> "" | _ -> let nl = List.map (fun x->Char.escaped x) l in List.fold_right (fun x y ->x^y) nl "";; |
let evens (max : int) : int list = let rec get_int pair i = if i >= max then [] else if (pair i) then i::get_int pair (i+1) else get_int pair (i+1) in get_int (fun x -> x mod 2 = 0) 0;; |
let fib (max : int) : int list = let rec fibonacci n = match n with 0|1 -> 1 | _ -> fibonacci(n-1)+fibonacci(n-2) in let rec stop fibo m i = if (fibo i) > m then [] else (fibo i)::stop fibo m (i+1) in stop fibonacci max 0;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec g l a = match l with [] -> true |x::y -> if x=a then false else g y a in let rec f g allergens l = match l with [] -> true |x::y -> if (g allergens x) then true else f g allergens y in let rec allergy f g allergens cupcakes = match cupcakes with | [] -> [] | x::y -> match x with Cupcake(_,_,_,a) -> if (f g allergens a) then x::(allergy f g allergens y) else allergy f g allergens y in allergy f g allergens cupcakes;; |
let string_explode s = tabulate (function x -> s.[x]) (String.length s);; |
let string_implode l = String.concat "" (List.map (Char.escaped) l);; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.