text
stringlengths 0
601k
|
---|
let evens (max : int) : int list = let f (n : int) = (n, n+2) in let stop (n : int) = (n >= max) in unfold f stop 0 ;; |
let fib (max : int) : int list = let f (prev,curr) = ((prev, curr), (curr, prev+curr)) in let stop (pre, cur) = (cur >= max) in let tup_list = unfold f stop (1,1) in let rec construct_list (l : ('a*'a) list) : 'a list = match l with |[] -> [] |[x] -> let (fst, last) = x in [last] |hd::tl-> let (fst,last) = hd in last::(construct_list tl) in match max with |0 -> [] |1 -> [] |_ -> 1::construct_list tup_list ;; |
let pascal (max : int) : int list list = let f (l : int list) = (l, List.map2 (+) ([0] @ l) (l @ [0])) in let stop l = ((List.length l) > max) in unfold f stop [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let isValid ingred = (List.mem ingred allergens) in let f (cake : cupcake) = let Cupcake(_,_,_,ingr) = cake in match ingr with |[] -> true |_ -> not (List.exists isValid ingr) in if(List.for_all f cupcakes) then cupcakes else match cupcakes with |[] -> [] |_ -> 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 str = List.map (Char.escaped) l in List.fold_left (^) "" str;; |
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,b),(c,d)) -> ((a,(b, b+a)),(c,d))) (fun ((a,b),(c,d)) -> max <= a) ((1,1),(1,1));; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter(function Cupcake (_,_,_,gees) -> List.for_all(fun x -> not ( List.exists((=) x) gees)) allergens) cupcakes;; |
let string_explode (s : string) : char list = let helper s func = tabulate (func) (String.length s) in helper s (String.get 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) -> (b, (b,a+b))) (fun (a,b) -> max <= b) (0,1) let exclude_last_element list = let rec helper list cur_list = match list with | head::[] -> cur_list | head::tail -> helper tail (head::cur_list) | _ -> cur_list in List.rev (helper list []);; |
let pascal (max : int) : int list list = let helper list = let l1 = exclude_last_element list and l2 = List.tl list and app_prepend list = List.append (1::list) [1] in app_prepend(List.map2 (+) l1 l2) in unfold (fun b -> (b, (helper b))) (fun b -> max < (List.length b)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let equals list val_ = not (List.exists ((=) val_) list) in let for_all = List.for_all (equals allergens) in let cupcake_tester c = let Cupcake(_,_,_,x) = c in for_all x in List.filter cupcake_tester 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 (String.concat) "" [[""];(List.map (Char.escaped) l)];; |
let evens (max : int) : int list = if max = 0 then [] else let add (seed: int) : (int * int) = (seed, seed + 2) in let stop (seed: int): bool = seed >= max in unfold add stop 0;; |
let fib (max : int) : int list = let step (seed: (int * int)) : (int * (int * int)) = ( snd seed , ( snd seed , snd(seed) + fst(seed)) ) in let stop (i: (int * int)): bool = snd i >= max in unfold step stop (0,1);; |
let pascal (max : int) : int list list = if max = 0 then [] else if max = 1 then [[1]] else let step (seed: int list) : (int list * int list) = let head = List.rev (List.tl (List.rev seed)) in let out = List.map2 (+) (List.tl seed) head in (seed, List.rev_append (List.append out [1]) [1]) in let stop (seed: int list) : bool = (List.nth seed 1) >= max in List.append [[1]] (unfold step stop [1;1]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if allergens = [] then cupcakes else let check_cupcakes ( c : cupcake ) : bool = let Cupcake (price,weight,calories,ingredients) = c in let check_allergens (alerg_ingr : ingredient) = if ingredients = [] then true else not (List.exists ((=) alerg_ingr) ingredients) in List.for_all check_allergens allergens in List.filter check_cupcakes cupcakes;; |
let string_explode (s : string) : char list = tabulate (fun n -> s.[n]) (String.length s) ;; |
let string_implode (l : char list) : string = List.fold_right (fun x s -> (Char.escaped x)^s) l "" ;; |
let evens (max : int) : int list = if max < 0 then failwith "not a natural number" else unfold (fun b -> (b,b+2) ) (fun b -> max <= b) 0 ;; |
let fib (max : int) : int list = if 1 >= max then [] else let f t = let s = fst t + snd t in (s,(snd t,s)) in 1 :: unfold f (fun t -> (fst t + snd t) >= max ) (0,1) ;; |
let pascal (max : int) : int list list = let next cur = List.map2 (+) ( 0 :: cur) (cur @ [0]) in unfold (fun b -> (b, next b)) (fun b -> List.length b > max ) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = if List.length allergens = 0 then cupcakes else if List.length allergens = 0 then [] else let f c = let Cupcake(_,_,_,ls) = c in List.for_all(fun x -> not (List.exists((=) x) allergens)) ls 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 = String.concat "" (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 = let does_exist x : bool= not (List.exists (fun y -> x = y) allergens) in let cup_check cup = let cup_i (Cupcake (_,_,_,i)) = i in let l = cup_i cup in List.for_all does_exist l in List.filter cup_check 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 a b -> Char.escaped a^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 nrow = fun (b) -> (b, List.map2 (+) (0 :: b) (b @ [0])) in unfold (nrow) (fun b -> max < List.length b) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,ingredients) -> List.for_all (fun ingredient -> not (List.exists ( fun allergen -> ingredient = allergen) allergens)) ingredients) 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 b -> match b with | [] -> (b, []) | _ -> let l1 = List.rev (0 :: List.rev b) in let l2 = 0 :: b in (b, List.map2 (+) l1 l2)) (fun b -> (max+1) <= (List.length b)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun b -> let Cupcake(_,_,_,ingredients) = b in List.for_all (fun allergen -> not (List.exists (fun ingredient -> ingredient = allergen) ingredients) ) 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_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 b -> let l1 = List.rev (0 :: List.rev b) in let l2 = 0 :: b in (b, List.map2 (+) l1 l2)) (fun b -> (max+1) <= (List.length b)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun b -> let Cupcake(_,_,_,ingredients) = b in List.for_all (fun allergen -> not (List.exists (fun ingredient -> ingredient = allergen) ingredients) ) 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_right (^) (List.map Char.escaped l) "" ;; |
let evens (max : int) : int list = unfold (fun s -> (s, s + 2)) ((<=) max) 0 ;; |
let fib (max : int) : int list = unfold (fun s -> (snd s, (snd s, fst s + snd s))) (fun s -> max <= snd s) (0,1) ;; |
let pascal (max : int) : int list list = unfold (fun s -> (s, List.map2 (+) (List.append s [0]) (List.rev (List.append s [0])))) (fun s -> max < List.length s) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (_,_,_,ilist) -> List.for_all (fun x -> not (List.exists (fun al -> al = x) allergens)) ilist) 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 (String.make 1) l) ;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) ((<=) max ) 0 ;; type seed = { n1: int; n2: int; } let seed = ref {n1 = 1; n2 = 0} let helper() = seed := {n1 = !seed.n1 + !seed.n2; n2 = !seed.n1}; !seed.n1;; |
let fib (max : int) : int list = seed := {n1 = 1; n2 = 0}; match max with |0 -> [] |1 -> [] | _ -> unfold (fun b-> match b with |0 -> (1, 1) |1 -> (b, b+1) |_ -> (b, b+helper()) ) ((<=) max ) 0 ;; let rec fact (n: int) = if n < 0 then domain () else (match n with | 0 -> 1. | _ -> (float_of_int n) *. (fact (n - 1))) let binomial (n: int) (k: int): int = if n < 0 then domain () else (if k > n then domain () else int_of_float ((fact n) /. ((fact k) *. fact (n - k)))) let helper2 (n:int) : int list = tabulate (binomial n) (n+1) ;; |
let pascal (max : int) : int list list = match max with |0 -> [] |_ -> unfold(fun b -> (helper2 b,b+1) ) ((<=) max ) 0 ;; let rec zip1 (l1 : 'a list) (l2 : 'b list) : ('a * 'b) list = match l1, l2 with | [], _ -> [] | _, [] -> [] | x::xs, y::ys -> (x, y) :: zip1 xs ys;; |
let allergy_free allergens = List.filter (function Cupcake (_,_,_,ingredients) -> List.for_all(function a -> List.for_all ((!=) a) ingredients) allergens);; |
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 to_str=List.map Char.escaped in let f = (^) in let l1= (to_str l) in List.fold_left (f) ("") l1;; |
let evens (max : int) : int list = if max <1 then [] else let f a = (a, a+2) in let compare i= (i=max) || (i=max+1) in unfold f compare 0;; |
let fib (max : int) : int list = if max <1 then [] else let f a = let (x,y)=a in a,(y, x+y) in let compare i= let (x,y)=i in (x>=max) in let (l1, l2)=List.split (unfold f compare (1,1)) in l1;; |
let pascal (max : int) : int list list = if max <1 then [] else let f a = let r = List.rev a in match a with |[1]-> a, [1;1] |x :: xs -> match r with |[] ->failwith "The provided list is empty." |y :: ys -> (a, List.concat [(List.concat [[1]; (List.map2 (+) (List.rev ys) xs)]); [1]]) in let rec len l = match l with |[]->0 |x :: xs -> 1+(len xs) in let compare i= (len i> max) in unfold f compare [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let diff_ing x i= not (x=i) in let rec f (allerg: ingredient list) c= let Cupcake (fl1,fl2,int,ing) = c in match allerg with |[]-> c |x :: xs->(if (List.for_all (diff_ing x) ing) then f xs c else Cupcake (-1., -1., -1, []) ) in let f1 = f allergens in let compare i= (Cupcake (-1., -1., -1, []) = f1 i) in let compare2 i= not (compare i ) in if (List.exists compare cupcakes) then List.filter compare2 cupcakes else 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 stringList = List.map Char.escaped l in let listStringConcat = List.fold_left (^) "" in listStringConcat stringList;; |
let evens (max : int) : int list = let f = (fun seed -> (seed, seed+2)) in let stop = (fun seed -> (seed >= (max))) in unfold f stop (0);; |
let fib (max : int) : int list = let f (seed:(int*int)) : ('a * (int*int)) = match seed with | (0,0) -> (1, (0,1)) | (0,1) -> (1, (1,1)) | (two_prev, prev) -> ((two_prev + prev), (prev, (two_prev + prev))) in let stop (seed:(int*int)) = let (two_prev, prev) = seed in (two_prev + prev) >= max || (max = 1) in unfold f stop (0,0);; |
let pascal (max : int) : int list list = let f (seed:(int list)) : ('a * (int list)) = if seed = [] then ([1], [1]) else let new_row = List.map2 (+) (List.append [0] seed) (List.append seed [0]) in (new_row, new_row) in let stop = (fun seed -> (List.length seed) >= max) in unfold f stop [];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let contains_allergen (c:cupcake) = let inAllergens (a:ingredient) = let equals_a = (=) a in not (List.exists equals_a allergens) in let Cupcake (_,_,_,ingred) = c in List.for_all inAllergens ingred in List.filter contains_allergen 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)) (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 b [0]) (List.rev_append [0] b))) (fun (b) -> max < List.length b) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function 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 curr = String.get s in let len = String.length s in tabulate curr len;; |
let string_implode (l : char list) : string = let charlis = List.map (Char.escaped) l in String.concat "" charlis;; |
let evens (max : int) : int list = unfold (fun e -> (e, e+2)) ((<=) max) 0;; |
let fib (max : int) : int list = unfold (fun (m,n) -> (m, (n,m+n))) (fun (m,n) -> max <= m) (1,1);; |
let pascal (max : int) : int list list = let remove_hd (l: 'a list) : 'a list = let hd::tl = l in tl in let remove_tl (l: 'a list) : 'a list = let revlist = List.rev l in let hd::tl = revlist in List.rev tl in let next_row l = let l1 = remove_hd l in let l2 = remove_tl l in List.map2 (+) l1 l2 in unfold (fun (l) -> (l, List.concat [ [1] ; (next_row l) ; [1] ])) (fun (l) -> max < List.length (l)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let i_is_a (i : ingredient) (a : ingredient) : bool = match i,a with | i,a when i == a -> true | _ -> false in let i_is_al (i : ingredient) : bool = not (List.exists (i_is_a i) allergens) in let il_is_al (il : ingredient list) : bool = List.for_all (i_is_al) il in let cup_has_a cup = let Cupcake (_,_,_,il) = cup in il_is_al il in List.filter (cup_has_a) cupcakes;; |
let string_explode (s : string) : char list = let curr = String.get s in let len = String.length s in tabulate curr len;; |
let string_implode (l : char list) : string = let charlis = List.map (Char.escaped) l in String.concat "" charlis;; |
let evens (max : int) : int list = unfold (fun e -> (e, e+2)) ((<=) max) 0;; |
let fib (max : int) : int list = unfold (fun (m,n) -> (m, (n,m+n))) (fun (m,n) -> max <= m) (1,1);; |
let pascal (max : int) : int list list = let remove_hd (l: 'a list) : 'a list = let hd::tl = l in tl in let remove_tl (l: 'a list) : 'a list = let revlist = List.rev l in let hd::tl = revlist in List.rev tl in let next_row l = let l1 = remove_hd l in let l2 = remove_tl l in List.map2 (+) l1 l2 in unfold (fun (l) -> (l, List.concat [ [1] ; (next_row l) ; [1] ])) (fun (l) -> max < List.length (l)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let ing_is_all (i : ingredient) (a : ingredient) : bool = match i with | a -> true | _ -> false in let ing_is_al_free (alist : ingredient list) (ing : ingredient) : bool = not (List.exists (ing_is_all ing) alist) in let il_has (il : ingredient list) (al : ingredient list) : bool = List.for_all (ing_is_al_free il) al in let cup_has allergy cup = let Cupcake (_,_,_,ing) = cup in (il_has allergens ing) in List.filter (cup_has allergens) cupcakes;; |
let string_explode (s : string) : char list = let l = String.length s in tabulate (fun x -> String.get s x) l;; |
let string_implode (l : char list) : string = let li = List.map Char.escaped l in String.concat "" li;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0 ;; |
let fib (max : int) : int list = if max=1 then [] else unfold (fun (a,b) -> (if b=0 then 1, (b,1+b) else a+b, (b,a+b))) (fun (a,b) -> max <= a+b) (0,0) ;; let rec fact (n: int): float = match n with | 0 -> 1. | _ -> float(n) *. fact(n - 1) let binomial (n: int) (k: int) : float = if n < 0 || k < 0 then domain () else (if k > n then domain () else fact(n) /. (fact(k) *. fact(n - k)));; |
let zip (l1 : 'a list) (l2 : 'b list) : ('a * 'b) list = unfold (fun (l,li) -> ((List.hd l, List.hd li),(List.tl l, List.tl li))) (fun (l,li) -> List.length l = 0 || List.length li =0) (l1,l2) ;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.