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 f stop ([],[],1);;
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 -> isSafe c 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 (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) 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 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) 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 (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::b -> el | _ -> 0) + (match b with | el1::el2::b -> el2 | _ -> 0) >= max ) ) [1;0];;
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 | [] ->[]) in List.append (List.rev (List.append newlist [1])) [1] ) , ( 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 | [] ->[]) in List.append (List.rev (List.append newlist [1])) [1]) ) ) (fun b -> max <= List.length b) [1] in let final = List.append (List.append (List.rev prelist) [[1;1]]) [[1]] in List.rev final ;;
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::b -> el | _ -> 0) + (match b with | el1::el2::b -> el2 | _ -> 0) >= max ) ) [1;0];;
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 | [] ->[]) in List.append (List.rev (List.append newlist [1])) [1] ) , ( 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 | [] ->[]) in List.append (List.rev (List.append newlist [1])) [1]) ) ) (fun b -> max <= List.length b) [1] in let final = List.append (List.append (List.rev prelist) [[1;1]]) [[1]] in List.rev final ;;
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::b -> el | _ -> 0) + (match b with | el1::el2::b -> el2 | _ -> 0) >= max ) ) [1;0];;
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 | [] ->[]) in List.append (List.rev (List.append newlist [1])) [1] ) , ( 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 | [] ->[]) in List.append (List.rev (List.append newlist [1])) [1]) ) ) (fun b -> max <= List.length b) [1] in let final = List.append (List.append (List.rev prelist) [[1;1]]) [[1]] in List.rev final ;;
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])) (fun l -> (List.length l) > max) [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 allergens) ingred_lst in List.filter (is_it_there) 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 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_it xs j in let is_it_there (c: cupcake) : bool = let Cupcake (_,_,_,ingred_lst) = c in find_it ingred_lst allergens in List.filter (is_it_there) cupcakes;;
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,current+2) ;; let rec fib_gen (fib:(int * int)) = let second=fst(fib)+snd(fib) and first=snd(fib) in (fib,(first,second)) ;;
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.length(input)>max ;; let calc_row (input:int list) : int list * int list= let add= 0 :: (remove_last input) and map=List.map2 (+) in input,((map input add)@[1]) ;;
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) :bool = let Cupcake (_,_,_,l) = c in f (function x->x !=i) l ;; let rec allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = match allergens with | [] ->cupcakes | _-> let contain=contain_allergen List.for_all (List.hd (allergens)) in let l=List.filter contain cupcakes and aller=List.tl allergens in allergy_free aller l ;;
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);;