text
stringlengths 0
601k
|
---|
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 = let fact x = let rec fact_ x acc = match x with | 0 -> acc | 1 -> acc | _ -> fact_ (x-1) (acc*x) in fact_ x 1 in let binom_coeffs n = unfold (fun a -> ((fact n)/((fact a)*(fact (n-a)))),a-1) (fun a -> a < 0) n in unfold (fun b -> (binom_coeffs b ,b + 1 )) ((<=) max) 0;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let not_in_list a = let looking_for x = x = a in not(List.exists looking_for allergens) in let check1 cupc = let Cupcake(_,_,_,t1) = cupc in List.for_all not_in_list t1 in List.filter check1 cupcakes;; |
let string_explode (s : string) : char list = let len = String.length s in let extract_char = String.get s in tabulate extract_char len ;; |
let string_implode (l : char list) : string = let l = List.map Char.escaped l in let concat s1 s2 = String.concat s1 ["";s2] in List.fold_left concat "" l;; |
let evens (max : int) : int list = unfold (fun b->(b, b+2)) ((<=) max) 0 ;; |
let fib (max : int) : int list = let take_b (a,b) = b in unfold (fun (a,b) -> (b,(b,a+b))) ( fun b -> max <= take_b 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) [1] ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_allergens b = not (List.for_all ((!=) b) allergens) in let remove_allergens (cup:cupcake) : bool = not( let Cupcake (a,b,c,allergens_in_cup) = cup in List.exists check_allergens allergens_in_cup ) in List.filter remove_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 (String.make 1) l);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = match cupcakes with | Cupcake (a, b, c, ingredients) :: xs -> List.filter (List.exists fun ingredients -> List.for_all ingredient.equals allergens) List.filter List.for_all not List.contains cupcakes let geting cp = match cp with | Cupcake (a,b,c,l) -> l let rec helper1 al cp= match al with | x :: xs -> List.filter (fun cp -> List.for_all ((<>) x) (geting cp)) cp let flip f x y = not (f y x) let rec helper al cp= List.filter (fun cp -> (List.for_all ((flip List.exists) (al))) (geting cp)) cp let h2 cping =;; |
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 let rec fib (max : int) : int list = unfold (fun (a, b) -> (b, (b, b+a))) (fun (a, b) -> max <= b) (0,1) let factorial n = let rec inner n acc = match n with | 0 | 1 -> acc | _ -> inner (n-1) (n*acc) in inner n 1 let binomial n k = (factorial n) / ((factorial k) * (factorial (n-k))) let helper n k= unfold (fun k -> ((binomial n k), (k-1))) (fun k -> k < 0) n;; |
let zip (l1 : 'a list) (l2 : 'b list) : ('a * 'b) list = unfold (zip3) (fun (a, b) -> (a = [] || b = [])) (l1, l2) let geting cp = let Cupcake (a,b,c,l) = cp in l let rec allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun cupcakes -> List.for_all (fun b -> (not(List.exists (fun a -> a = b) allergens))) (geting cupcakes)) 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 = let f = fun b -> let cur = List.nth b 2 in let prev = List.nth b 1 in (cur, [prev; cur; prev + cur]) in let stop = fun b -> max <= (List.nth b 2) in unfold (f) (stop) [0; 0; 1];; |
let pascal (max : int) : int list list = let f = fun b -> if b = [] then ([1], [[1]]) else let l1 = List.tl (List.nth b (List.length b - 1)) in let l2 = List.rev (l1) in let nr = List.rev_append (List.append (List.map2 (+) l1 l2) [1]) [1] in (nr, List.append b [nr]) in let stop = fun b -> max <= (List.length b) in unfold (f) (stop) [];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let contains_allergens allergens = function Cupcake (_, _, _, ingred_lst) -> let without_ingredient ingred_lst = fun allergen -> not (List.exists ((=) allergen) ingred_lst) in List.for_all (without_ingredient ingred_lst) allergens in List.filter (contains_allergens 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 (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 (a, b) -> (a, ((List.map2 (+) (0 :: a) (a @ [0])), b + 1))) (fun (a, b) -> max <= b) ([1], (0)) ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (_, _, _, il)) -> List.for_all (fun i -> not (List.exists (fun a -> (a = i)) allergens)) il) cupcakes ;; |
let string_explode (s : string) : char list = tabulate (fun c -> String.get s c) (String.length s);; |
let string_implode (l : char list) : string = let s_list = List.map Char.escaped l in List.fold_left (fun acc cur_string -> acc ^ cur_string) "" 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 pascal (max : int) : int list list = unfold (fun row -> (row, let row_x = List.append row [0] in let row_y = List.append [0] row in List.map2 (fun x y -> x + y) row_x row_y)) (fun row -> max < List.length row) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (_,_,_,ingred_lst)) -> match ingred_lst with |[] -> true |_ -> List.for_all (fun ingredient -> not (List.exists (fun allergen -> allergen = ingredient) allergens)) ingred_lst ) 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 = let next_fib (b0, b1) = b1, (b1, b0 + b1) in unfold (next_fib) (fun (b0, b1) -> max <= b1) (0, 1);; |
let pascal (max : int) : int list list = let next_row (n, l) = l, ((n+1), (List.map2 (+) (0 :: l) (l @ [0]))) in unfold (next_row) (fun (n, l) -> max <= n) (0, [1]);; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( fun (Cupcake (_, _, _, ingredients)) -> List.for_all ( fun (allergen: ingredient) -> not (List.exists ((=) allergen) ingredients) ) allergens ) 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 = List.fold_left(^)("")(List.map Char.escaped l);; |
let evens (max : int) : int list = if max = 0 then [] else unfold(fun b -> (b, b+2))(fun b -> max <= b) 0;; |
let fib (max : int) : int list = let (c,d)= (1,1) in unfold( fun(a,b) -> (a, (b, a+b)))( fun (a,b) -> max <=a)(c,d);; |
let pascal (max : int) : int list list = unfold( fun b ->(b, List.map2 (+) (0 :: b) (b @ [0])))(fun b -> max <= List.length(b) - 1) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list= let get_cupcakes = fun (cupcake) -> match cupcake with | Cupcake(p',w',c',i') -> if List.length i' = 0 then true else if List.for_all(contains(allergens))(i') then false else if List.exists(contains(allergens))(i') then false else true in List.filter get_cupcakes 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 (fun c -> (^) (Char.escaped c)) l "";; |
let evens (max : int) : int list = unfold (fun x -> (x, x+2)) (fun x -> x >= max) 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 x -> (x, List.map2 (+) (0::x) (List.rev ((0::(List.rev x)))))) (fun x -> (List.length x) > max) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( fun c -> let Cupcake(_, _, _, ingr) = c in List.for_all (fun i -> not (List.exists ((=) i) 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.fold_right (fun c -> (^) (Char.escaped c)) l "";; |
let evens (max : int) : int list = unfold (fun x -> (x, x+2)) (fun x -> x >= max) 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 x -> (x, List.map2 (+) (0::x) (List.rev ((0::(List.rev x)))))) (fun x -> (List.length x) > max) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter ( fun (Cupcake(_,_,_,ingr)) -> List.for_all (fun i -> not (List.exists ((=) i) allergens)) ingr ) cupcakes;; |
let string_explode (s : string) : char list = let same x = x in let get_from_s = String.get s in let tabulated = tabulate same (String.length s) in List.map get_from_s tabulated;; |
let string_implode (l : char list) : string = let string_and_concat c = (^) (Char.escaped c) in List.fold_right string_and_concat l "";; |
let evens (max : int) : int list = let gen_next even = even, (even+2) in let stop_at curr = curr>=max in unfold gen_next stop_at 0;; |
let fib (max : int) : int list = let gen_next seed = snd seed, (snd seed, fst seed + snd seed) in let stop_at curr = snd curr>= max in unfold gen_next stop_at (0, 1);; |
let pascal (max : int) : int list list = let gen_next seed = seed, List.map2 (+) (0::seed) (List.append seed [0]) in let stop_at curr = List.length curr > max in unfold gen_next stop_at [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_cupcake c = let Cupcake(p, w, c, ingreds) = c in let inlist item = not (List.exists ((=) item) allergens) in List.for_all inlist ingreds in List.filter check_cupcake cupcakes;; |
let string_explode (s : string) : char list = let index = tabulate (fun x->x) (String.length s) in List.fold_right (fun x acc -> (String.get s x) :: acc) index [];; |
let string_implode (l : char list) : string = let strList = List.map Char.escaped l in List.fold_left (^) "" strList;; |
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 b -> max <= (fst b)) (1,1);; |
let pascal (max : int) : int list list = unfold (fun a -> (a, List.map2 (+) (0::a) (List.append a [0]))) (fun b -> max +1<= List.length b) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun c -> match c with |Cupcake (_,_,_,[]) -> List.for_all (fun a-> true) [] |Cupcake (_,_,_,l) -> not (List.exists (fun a -> List.mem a allergens) l) ) cupcakes;; |
let string_explode (s : string) : char list = tabulate (fun a -> String.get s a) (String.length s);; |
let string_implode (l : char list) : string = let new_list = List.map (fun a -> Char.escaped a) l in List.fold_left (^) "" 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) -> a > (max-1)) (1, 1) ;; |
let pascal (max : int) : int list list = let pascal_row (p: int list): int list = match p with | [] -> [] | [1] -> [1; 1] | h::t -> [1] @ (List.map2 (+) (List.rev t) t) @ [1] in unfold (fun p -> (p, (pascal_row p))) (fun p -> (max < List.length p)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_allergens (cup: cupcake) (ingred : ingredient): bool = match cup with | Cupcake (_, _, _, []) -> true | Cupcake (_, _, _, ingred_lst) -> not (List.exists (fun a -> a = ingred) ingred_lst) in List.filter (fun b -> List.for_all (check_allergens b) allergens ) cupcakes;; |
let string_explode (s : string) : char list = let f x = x in let int_list = tabulate (f) (String.length s) in List.map (String.get s) int_list ;; |
let string_implode (l : char list) : string = let str_list = List.map (Char.escaped) (l) in List.fold_left (^) "" str_list ;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0 ;; |
let fib (max : int) : int list = let rec fib_aux (n: int) (a: int) (b: int) = if n = 0 then a else if n = 1 then b else fib_aux (n-1) (b) (a+b) in let fib_tl n = fib_aux (n) 0 1 in unfold (fun b -> (fib_tl b, b+1)) (fun b -> max <= fib_tl b) 1 ;; |
let pascal (max : int) : int list list = let rec get_nth_row (cur: int) (n: int) (l: int list) : int list = if cur = n then l else let zero_l = 0::l in let l_zero = List.rev (0::(List.rev l)) in get_nth_row (cur+1) (n) (List.map2 (+) zero_l l_zero) in unfold (fun b -> (get_nth_row 1 b [1], b+1)) (fun b -> max < b) 1 ;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.exists (fun b -> true) cupcakes; List.for_all (fun b -> true) cupcakes; let get_4th (Cupcake (_,_,_,a)) = a in let rec f (al: ingredient list) (cup: cupcake) : bool = if (List.length al = 0) then true else let a = List.hd al in if List.mem (a) (get_4th cup) then false else f (List.tl al) (cup) in List.filter (f allergens) (cupcakes) ;; |
let string_explode (s : string) : char list = List.fold_right (fun i acc -> (String.get s i) :: acc) (tabulate (fun x -> x) (String.length s)) [];; |
let string_implode (l : char list) : string = let l_str = List.map (Char.escaped) l in List.fold_left (^) "" l_str;; |
let evens (max : int) : int list = unfold (fun b -> (b, b + 2)) ((<=) max) 0;; |
let fib (max : int) : int list = if max <= 1 then [] else let pairs = unfold (fun (b, c) -> ((b, c), (c, b + c))) (fun (b, c) -> max <= c) (1, 1) in 1 :: (List.fold_right (fun (b, c) acc -> (c :: acc)) pairs []);; |
let pascal (max : int) : int list list = if max = 1 then [[1]] else unfold (fun l -> (l, List.map2 (+) (0 :: l) (List.append l [0]))) (fun l -> max < (List.length l)) [1];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (a, b, c, ingredients)) -> List.for_all (fun ingredient -> not (List.exists (fun allergen -> allergen = ingredient) allergens) ) ingredients) cupcakes;; |
let string_explode (s : string) : char list = let index n= s.[n] in tabulate index (String.length s);; |
let string_implode (l : char list) : string = let concat2 (a: char) (b:string)= (Char.escaped a)^b in List.fold_right (concat2) 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 rec fib n = match n with |0 -> 1 |1 -> 1 |x-> (fib (x-2) + fib (x-1)) in unfold (fun b -> (fib b, b+1)) (fun b -> max <= fib b) 0;; |
let pascal (max:int): int list list= let r2 r1= List.map2 (+) (List.append [0] r1) (List.append r1 [0]) in let rec pascal n = if n = 0 then [1] else r2 (pascal (n-1)) in unfold (fun b -> (pascal b, b+1)) (fun b -> max <= b) 0;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let equa a b= a==b in let nott i= not ( List.exists (equa i) allergens) in let hypo c = let Cupcake (_,_,_,ingred_list) = c in List.for_all nott ingred_list in List.filter hypo cupcakes;; |
let domain () = failwith "REMINDER: You should not be writing tests for undefined values." let rec tabulate f n = let rec tab n acc = if n < 0 then acc else tab (n - 1) ((f n) :: acc) in tab (n - 1) [] let rec unfold (f : 'seed -> 'a * 'seed) (stop : 'seed -> bool) (b : 'seed) : 'a list = if stop b then [] else let (x, b') = f b in x :: unfold f stop b' let nats max = unfold (fun b -> (b, b+1)) (fun b -> max <= b) 0 type price = float type weight = float type calories = int type ingredient = Nuts | Gluten | Soy | Dairy type cupcake = Cupcake of price * weight * calories * ingredient list let c1 = Cupcake (2.5, 80.3, 250, [Dairy; Nuts]) let c2 = Cupcake (2.75, 90.5, 275, [Dairy; Soy]) let c3 = Cupcake (3.05, 100.4, 303, [Dairy; Gluten; Nuts]) let c4 = Cupcake (3.25, 120.4, 330, [Dairy; Gluten ]) let cupcakes = [c1 ; c2 ; c3 ; c4];; |
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 = if(max<1) then [] else let plusTwo (x:int) : (int*int) = (x+2,x+2) in let reachedMax (x:int) :bool = (x+2>=max) in unfold plusTwo reachedMax (-2);; |
let fib (max : int) : int list = if(max<2)then [] else let sumPair ((x,y) : (int*int)) : (int*(int*int)) = if(x=0 && y=0) then (1,(0,1)) else (x+y,(y,x+y)) in let reachedSummit ((x,y):(int*int)) : bool = (x+y>=max) in unfold sumPair reachedSummit (0,0);; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.