text
stringlengths
0
601k
let pascal (max : int) : int list list = let f (l: int list) : (int list) * (int list) = (l, [1] @ (List.map2 (+) (List.tl l) (List.rev (List.tl (List.rev l)))) @ [1]) in unfold f (fun l -> max < List.length l) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let check_allergies (Cupcake (_, _, _,(l: ingredient list))) : bool = (List.for_all (fun a -> not (List.exists (fun i -> i = a) l)) allergens) in List.filter check_allergies cupcakes ;;
let string_explode (s : string) : char list = let get_char n = String.get s n in tabulate get_char (String.length s);;
let string_implode (l : char list) : string = if (List.length l) = 0 then "" else let str_list = List.map (Char.escaped) l in String.concat "" str_list;;
let evens (max : int) : int list = let f seed = (seed, seed + 2) in let stop seed = seed >= max 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 in unfold f stop (0, 1);;
let pascal (max : int) : int list list = let f (list1, list2, n) = match n with | 1 -> ([1], ([], [], 2)) | 2 -> ([1;1],([1], [1], 3)) | _ -> let join_list = List.map2 (+) list1 list2 in (1::(List.rev (1::join_list)), ((1::join_list), (List.rev (1::join_list)), n + 1)) in let stop (list1, list2, n) = n > max in unfold ...
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let not_allergen a = not (let has x = (x = a) in List.exists has allergens) in let safety_check cake = let Cupcake (_,_,_,ingredient) = cake in List.for_all not_allergen ingredient in List.filter safety_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 l -> (l, l+2)) ( fun l -> l >= 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 = raise NotImplemented;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (_, _, _, l)) -> List.for_all (fun i -> not(List.exists ((=) i) allergens)) l) cupcakes;;
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);;
let string_implode (l : char list) : string = let list_of_string = List.map(fun x -> Char.escaped x) l in String.concat "" list_of_string;;
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 (x,y) -> (x, (y,x+y))) (fun (x,y) -> max <= x) (1,1);;
let pascal (max : int) : int list list = unfold (fun x -> (x, List.map2 (+) (List.append [0] x) (List.append x [0]))) (fun x -> max < List.length x) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let isSafe (aCupcake : cupcake) (allergens : ingredient list) : bool = let Cupcake(p,w,c,ingredient_list) = aCupcake in List.for_all (fun i -> not (List.exists (fun a -> a = i) allergens)) ingredient_list in List.filter (fun c -> ...
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 e -> (e, e+2)) ((<=) max) 0;;
let fib (max : int) : int list = let f = fun (fn1,fn2) -> (fn1, (fn1+fn2,fn1)) in unfold (f) (fun (fn1,fn2) -> max <= fn1) (1,0);;
let pascal (max : int) : int list list = unfold (fun ls -> (ls, List.map2 (+) (0::ls) (ls @ [0]))) (fun ls -> max < List.length ls) ([1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let helper2 ingredient : bool = (not (List.exists (fun i -> i = ingredient) allergens)) in let helper allergens cupcake : bool = let Cupcake (_,_,_,ls) = cupcake in (List.for_all (helper2) ls) in List.filter (helper allergens) cup...
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 e -> (e, e+2)) ((<=) max) 0;;
let fib (max : int) : int list = let f = fun (fn1,fn2) -> (fn1, (fn1+fn2,fn1)) in unfold (f) (fun (fn1,fn2) -> max <= fn1) (1,0);;
let pascal (max : int) : int list list = unfold (fun ls -> (ls, List.map2 (+) (0::ls) (ls @ [0]))) (fun ls -> max < List.length ls) ([1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let helper2 ingredient : bool = (not (List.exists (fun i -> i = ingredient) allergens)) in let helper allergens cupcake : bool = let Cupcake (_,_,_,ls) = cupcake in (List.for_all (helper2) ls) in List.filter (helper allergens) cup...
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,...
let string_explode (s : string) : char list = tabulate (fun x -> String.get s x) (String.length s);;
let string_implode (l : char list) : string = let strlist = List.map (fun x -> Char.escaped x) l in List.fold_left (fun x y -> x^y) "" 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 b -> ( ( (match b with | el::b -> el | _ -> 0) + (match b with | el2::el1::b -> el1 | _ -> 0) ) , (match b with | el::el2::b -> el2 | _ -> 0):: ( (match b with | el::b -> el | _ -> 0) + (match b with | el2::el1::b -> el1 | _ -> 0) )::[] ) ) ( fun b -> ( (match b with | el::...
let pascal (max : int) : int list list = if max = 0 then [] else if max = 1 then [[1]] else if max = 2 then [[1];[1;1]] else let prelist = unfold ( fun b -> ( ( let newlist = List.map2 (fun x y -> x+ y) (match b with | [1] -> [1] | x::xs -> xs | [] ->[]) (match (List.rev b) with | [1] -> [1] | x::xs -> List.rev xs | []...
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;;
let string_explode (s : string) : char list = tabulate (fun x -> String.get s x) (String.length s);;
let string_implode (l : char list) : string = let strlist = List.map (fun x -> Char.escaped x) l in List.fold_left (fun x y -> x^y) "" 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 b -> ( ( (match b with | el::b -> el | _ -> 0) + (match b with | el2::el1::b -> el1 | _ -> 0) ) , (match b with | el::el2::b -> el2 | _ -> 0):: ( (match b with | el::b -> el | _ -> 0) + (match b with | el2::el1::b -> el1 | _ -> 0) )::[] ) ) ( fun b -> ( (match b with | el::...
let pascal (max : int) : int list list = if max = 0 then [] else if max = 1 then [[1]] else if max = 2 then [[1];[1;1]] else let prelist = unfold ( fun b -> ( ( let newlist = List.map2 (fun x y -> x+ y) (match b with | [1] -> [1] | x::xs -> xs | [] ->[]) (match (List.rev b) with | [1] -> [1] | x::xs -> List.rev xs | []...
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;;
let string_explode (s : string) : char list = tabulate (fun x -> String.get s x) (String.length s);;
let string_implode (l : char list) : string = let strlist = List.map (fun x -> Char.escaped x) l in List.fold_left (fun x y -> x^y) "" 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 b -> ( ( (match b with | el::b -> el | _ -> 0) + (match b with | el2::el1::b -> el1 | _ -> 0) ) , (match b with | el::el2::b -> el2 | _ -> 0):: ( (match b with | el::b -> el | _ -> 0) + (match b with | el2::el1::b -> el1 | _ -> 0) )::[] ) ) ( fun b -> ( (match b with | el::...
let pascal (max : int) : int list list = if max = 0 then [] else if max = 1 then [[1]] else if max = 2 then [[1];[1;1]] else let prelist = unfold ( fun b -> ( ( let newlist = List.map2 (fun x y -> x+ y) (match b with | [1] -> [1] | x::xs -> xs | [] ->[]) (match (List.rev b) with | [1] -> [1] | x::xs -> List.rev xs | []...
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;;
let string_explode (s : string) = List.map (String.get s) (tabulate (fun x -> x) (String.length s)) ;;
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 s -> (s, s+2)) (fun s -> (s >= max)) (0) ;;
let fib (max : int) : int list = unfold (fun (s1, s2) -> (s1, (s2, s1+s2))) (fun (s1, s2) -> (s1 >= max)) ((1,1)) ;;
let pascal (max : int) : int list list = unfold (fun (prev_r, new_r) -> (prev_r, (new_r, ( let list_1 = new_r @ [0] in let list_2 = 0 :: new_r in List.map2 (+) list_1 list_2 )))) (fun (prev_r, new_r) -> ((List.length prev_r) > max)) ([1], [1;1]) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun (Cupcake (price, weight, calories, ingredients)) -> List.for_all (fun ingredient -> not (List.exists (fun allergen -> allergen = ingredient) 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_left (fun s-> fun c-> s^(Char.escaped c)) "" 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 (b,c) -> ((c),(c,b+c))) (fun (b,c) -> c >= max) (0,1);;
let pascal (max : int) : int list list = let header l = match l with | [] -> failwith "List too small." |_::tl -> tl in let tailer l = match List.rev l with | [] -> failwith "List too small." |_::tl -> List.rev tl in let helper l:int list = List.map2 (+) (header l) (tailer l) in unfold (fun l -> (l,1::(helper l)@[1])) ...
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let sep c a= let Cupcake (_,_,_,ls)= c in not (List.exists ( (=) a) ls) in let verify c = List.for_all (sep c) allergens in List.filter (verify) 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 = 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) -> (a, (b,a+b))) (fun (a,b) -> max <= a) (1,1);;
let pascal (max : int) : int list list = unfold(fun l -> (l, List.map2 (+) (List.append l [0]) (List.rev (List.append (List.rev l) [0])))) (fun b -> max <= (List.length b) - 1) [1];;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (fun l -> let Cupcake (_,_,_,ingredients) = l in List.for_all (fun x -> not (List.exists ((=) x) allergens)) ingredients) 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 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)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a,b) -> (a,(b, a+b))) (fun (a,b) -> (max,b) <= (a,b)) (1,1);;
let pascal (max : int) : int list list = let next (l:int list) : int list = List.map2 (+) (0::l) (List.rev (0::(List.rev l))) in unfold (fun (a,b) -> (a,(b, (next b)))) (fun (a,b) -> (List.length a > max)) ([1],[1;1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec find_it (i: ingredient list) (j: ingredient) : bool= let looking_for = (=) in not (List.exists (looking_for j) i) in let is_it_there (c: cupcake) : bool = let Cupcake (_,_,_,ingred_lst) = c in List.for_all (find_it allerge...
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 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)) ((<=) max) 0;;
let fib (max : int) : int list = unfold (fun (a,b) -> (a,(b, a+b))) (fun (a,b) -> (max,b) <= (a,b)) (1,1);;
let pascal (max : int) : int list list = let next (l:int list) : int list = List.map2 (+) (0::l) (List.rev (0::(List.rev l))) in unfold (fun (a,b) -> (a,(b, (next b)))) (fun (a,b) -> (List.length a > max)) ([1],[1;1]);;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec find_it (i: ingredient list) (j: ingredient list) : bool= let looking_for = (=) in match i with | [] -> (let p = Nuts in (List.for_all (looking_for p) i)) | x::xs -> if (List.exists (looking_for x) j) then false else find_...
let string_explode (s : string) : char list = tabulate (fun character -> String.get s character) ((String.length s));;
let string_implode (l : char list) : string = List.fold_left (fun s c -> s ^ String.make 1 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 (a,b) -> (a,(b,a+b))) (fun (a,b) -> a >= max) (1,1);;
let pascal (max : int) : int list list = unfold (fun (row,depth) -> (row,((List.map2 (+) (row@[0]) (0::row)),depth-1))) (fun (row,depth) -> depth <= 0) ([1], max) ;;
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = List.filter (function Cupcake (price, weight, calories, ingredient_list) -> List.for_all (fun a -> not (List.exists (fun x -> x = a) ingredient_list)) allergens ) cupcakes;;
let string_explode (s : string) : char list = let get=String.get s and length=String.length s in tabulate get length;;
let string_implode (l : char list) : string = let string_l=List.map Char.escaped l in List.fold_right (^) string_l "" let limit (max :int) (current:int) :bool= not (current<max) ;; let limit_tuple (max :int) (current: int * int) :bool= not (fst(current)<max) ;; let even_generate (current:int): int *int= (current,curren...
let evens (max : int) : int list = let max_fun=limit max in unfold even_generate max_fun 0;;
let fib (max : int) : int list = let max_fun=limit_tuple max in let tuple_list=unfold fib_gen max_fun (1,1) in let split=List.split(tuple_list) in fst(split) ;; let remove_last (l: 'a list):'a list= let rev_l=List.rev l in let tl_l=List.tl rev_l in List.rev tl_l ;; let max_length (max:int)(input:int list) : bool = List...
let zip (l1 : 'a list) (l2 : 'b list) : ('a * 'b) list = if(List.length l1 != List.length l2) then let result=unfold combine stop_zip ([],(l1,l2)) in let a=fst((List.split(result))) in List.hd(List.rev(a)) else List.combine l1 l2 ;; let contain_allergen (f:('a -> bool) -> 'a list -> bool)(i : ingredient) (c : cupcake) ...
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);;