text
stringlengths
0
601k
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((a,b), val_), (c, d) = ((from_unit, val_), to_unit) in (a, b), second (convert_dist (a, val_) c) /. second (convert_time (b, 1.) d) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, second (convert_speed (a) (b_unit)) +. b_val) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch (width, subtree) :: tl -> sum_ tl (acc +. width ** 2.) in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> if not (check subtree && sum_ subtree 0. <= width ** 2....
let mode (l: 'a list) : 'a = let rec aux l ((prev_el, prev_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if prev_num < max_num then max_el else prev_el | h :: t -> aux t (if h = prev_el then (prev_el, prev_num + 1) else (h, 1)) (if prev_num >= max_num then (prev_el, prev_num + 1) else (max_el, ...
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (list_remaining: 'a list) (list_built: ('a * 'a) list) = match list_remaining with | [] -> failwith "Empty list" | [ _ ] -> failwith "Too few elements" | item1 :: [ item2 ] -> (item1, item2) :: list_built | h1 :: h2 :: t -> aux (h2 :: t) ((h1, h2) :: list_built) in mod...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Hour, Hour) | (Second, Second) -> (to_unit, val_) | (Second, Hour) -> (Hour, val_ /. 3600.) | (Hour, Second) -> (Second, val_ *. 3600.) ;; let rec convert_dist ((from_unit, val_) : dist_unit value) to_u...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_dist, from_time) = from_unit in let (to_dist, to_time) = to_unit in (to_unit, snd (convert_time (to_time, (snd (convert_dist (from_dist, val_) to_dist))) from_time)) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (target_distance_unit, target_time_unit) = speed_unit in let time_val_converted = snd (convert_time time target_time_unit) in (target_distance_unit, time_val_converted *. speed_val) ;; let tree0 = Branch (5., [ Branch (3., [Leaf...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if max_num >= cur_num then max_el else cur_el | x :: xs -> if x = cur_el then aux xs (x,cur_num+1) (max_el,max_num) else ( if x != cur_el && cur_num > max_num then aux xs (x,1) (cur_el,cur_num...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Invalid Input: empty list" | [_] -> failwith "Invalid Input: no pair exists" | _ -> let l2 = List.combine l (List.tl l @ [List.hd l]) in let l3 = List.tl (List.rev l2) in mode l3 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Hour,Second) -> (Second,val_ *. 3600.) | (Second,Hour) -> (Hour,val_ /. 3600.) | (_,_) -> (to_unit,val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit,to_unit) with | (Foot,Mile) -> (Mile,val_ /. 5280.) | (Mile,Foot) -> (Foot,val_ *. 5280.) | (Foot,Meter) -> (Meter,val_ *. 0.3048) | (Meter,Foot) -> (Foot,val_ /. 0.3048) | (Meter,Mile) -> (Mile,val_ /. 0.3048 /. 5280.) ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist_unit,from_time_unit),(to_dist_unit,to_time_unit)) = (from_unit, to_unit) in let dist = convert_dist (from_dist_unit,val_) to_dist_unit in let time = convert_time (from_time_unit,1.) to_time_unit in let ((d_unit,d_value...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_speed = convert_speed a b_unit in let (_,a_val) = a_speed in (b_unit,a_val +. b_val) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch (val',l) -> let rec helper l = match l with | [] -> true | x::xs -> match x with | Leaf -> true && helper xs | Branch (val_,l_) -> (cal_sum l_ <= val_ *. val_) && helper l_ && helper xs in (cal_sum l <= val' *. val') && helper l;;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if max_num >= cur_num then max_el else cur_el | x :: xs -> if x = cur_el then aux xs (x,cur_num+1) (max_el,max_num) else ( if x <> cur_el && cur_num > max_num then aux xs (x,1) (cur_el,cur_num...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Invalid Input: empty list" | [_] -> failwith "Invalid Input: no pair exists" | _ -> let l2 = List.combine l (List.tl l @ [List.hd l]) in let l3 = List.tl (List.rev l2) in mode l3 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Hour,Second) -> (Second,val_ *. 3600.) | (Second,Hour) -> (Hour,val_ /. 3600.) | (_,_) -> (to_unit,val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit,to_unit) with | (Foot,Mile) -> (Mile,val_ /. 5280.) | (Mile,Foot) -> (Foot,val_ *. 5280.) | (Foot,Meter) -> (Meter,val_ *. 0.3048) | (Meter,Foot) -> (Foot,val_ /. 0.3048) | (Meter,Mile) -> (Mile,val_ /. 0.3048 /. 5280.) ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist_unit,from_time_unit),(to_dist_unit,to_time_unit)) = (from_unit, to_unit) in let dist = convert_dist (from_dist_unit,val_) to_dist_unit in let time = convert_time (from_time_unit,1.) to_time_unit in let ((d_unit,d_value...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_speed = convert_speed a b_unit in let (_,a_val) = a_speed in (b_unit,a_val +. b_val) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch (val',l') -> (cal_sum l' <= val' *. val') && tree_branch l' ;;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if max_num >= cur_num then max_el else cur_el | x :: xs -> if x = cur_el then aux xs (x,cur_num+1) (max_el,max_num) else ( if x <> cur_el && cur_num > max_num then aux xs (x,1) (cur_el,cur_num...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Invalid Input: empty list" | _ -> let l2 = List.combine l (List.tl l @ [List.hd l]) in let l3 = List.tl (List.rev l2) in match l3 with | [] -> failwith "Invalid Input: no pair exists" | _ -> mode l3 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Hour,Second) -> (Second,val_ *. 3600.) | (Second,Hour) -> (Hour,val_ /. 3600.) | (_,_) -> (to_unit,val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit,to_unit) with | (Foot,Mile) -> (Mile,val_ /. 5280.) | (Mile,Foot) -> (Foot,val_ *. 5280.) | (Foot,Meter) -> (Meter,val_ *. 0.3048) | (Meter,Foot) -> (Foot,val_ /. 0.3048) | (Meter,Mile) -> (Mile,val_ /. 0.3048 /. 5280.) ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist_unit,from_time_unit),(to_dist_unit,to_time_unit)) = (from_unit, to_unit) in let dist = convert_dist (from_dist_unit,val_) to_dist_unit in let time = convert_time (from_time_unit,1.) to_time_unit in let ((d_unit,d_value...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_speed = convert_speed a b_unit in let (_,a_val) = a_speed in (b_unit,a_val +. b_val) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch (val',l') -> (cal_sum l' <= val' *. val') && tree_branch l' ;;
let getFirst (l: 'a list) : 'a = match l with | x::xs -> x | _ -> failwith "empty list";;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> (match cur_num > max_num with | true -> cur_el | false -> max_el ) | x::xs -> (match x = cur_el with | true -> aux xs (cur_el, cur_num+1) (max_el, max_num) | false -> (match cur_num > max_num ...
let pair_mode (l: 'a list) : 'a * 'a = mode (List.combine (remLast l) (remFirst l)) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (match to_unit with | Hour -> (Hour, val_ /. 3600.) | _ -> (Second, val_)) | Hour -> (match to_unit with | Second -> (Second, val_ *. 3600.) | _ -> (Hour, val_)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> (match to_unit with | Meter -> (Meter, val_ *. 0.3048) | Mile -> (Mile, val_ /. 5280.) | _ -> (Foot, val_)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Mile -> (Mile, val_ /. 0.3048 /....
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match to_unit with | (Foot, Second) -> ((Foot, Second), getT2 (convert_dist (getT1 from_unit, getT2 (convert_time (getT2 to_unit, val_) (getT2 from_unit))) Foot)) | (Meter, Second) -> ((Meter, Second), getT2 (convert_dist (getT1 from_...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = match speed_unit with | (Foot, Second) -> (Foot, (getT2 time) *. (getT3 (convert_speed ((Foot, Second), speed_val) (Foot, getT1 time)))) | (Meter, Second) -> (Meter, (getT2 time) *. (getT3 (convert_speed ((Meter, Second), speed_val)...
let mode (l: 'a list) : 'a = let rec aux l (cl,cn) (ml,mn) : 'a = match l with | [] -> ml | hd :: tl -> if cl = hd then if cn >= mn then aux tl (hd,cn+1) (cl,cn+1) else aux tl (hd,cn+1) (ml,mn) else aux tl (hd,1) (ml,mn) in match List.sort compare l with | [] -> failwith "Empty List." | h::t -> aux t (h,1) (h,1) ;;
let pair_mode (l: 'a list) : 'a*'a = match l with | _::[] -> failwith "This list has only 1 element!" | [] -> failwith "This list is empty!" | _ -> let (_ :: no_head) = l in let (_ :: no_tail) = (List.rev l) in mode (List.combine (List.rev no_tail) no_head) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit,to_unit with | Second, Second -> (to_unit,val_) | Second, Hour -> (to_unit,val_ /. 3600.) | Hour,Second -> (to_unit,3600. *. val_) | Hour,Hour -> (to_unit,val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit,to_unit with | Foot, Meter -> (to_unit,val_ *. 0.3048) | Foot, Mile -> (to_unit,val_ /. 5280.) | Meter,Foot -> (to_unit,val_ /. 0.3048) | Meter,Mile -> (to_unit,val_ /. 1609.344) | Mile, Foot -> (to_unit,val_ *. 5280.) | ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist1 = snd (convert_dist (fst from_unit, val_) (fst to_unit)) in let inv1 = snd (convert_time (snd from_unit, 1.) (snd to_unit)) in (to_unit, dist1 /. inv1) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let t = snd(convert_time (fst time,snd time) (snd speed_unit)) in let res = speed_val *. t in (fst speed_unit,res) ;; let get_width (t : tree) : float = match t with | Leaf -> 0. | Branch (w, _) -> w ;; let rec iter t = match t with...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | hd :: tl -> (if compare hd cur_el == 0 then (if compare hd max_el == 0 then aux tl (cur_el, cur_num +1) (max_el, max_num+1) else (if cur_num +1 >...
let pair_mode (l: 'a list) : 'a * 'a = if l == [] || List.length l == 1 then failwith "List not long enough" else ( let l1 = l in let l2 = l in let (_ :: no_head1) = l1 in let (_ :: no_head2) = List.rev l2 in mode (List.combine (List.rev no_head2) no_head1) ) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (to_unit, val_ /. 3600.) | (Hour, Second) -> (to_unit, val_ *. 3600.) | _ -> (to_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (to_unit, val_ *. 0.3048) | (Meter, Foot) -> (to_unit, val_ /. 0.3048) | (Foot, Mile) -> (to_unit, val_ /. 5280.) | (Mile, Foot) -> (to_unit, val_ *. 5280.) | (Meter, Mile) -> (to_unit, ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (to_unit, snd(convert_dist ((fst(from_unit)), val_) (fst(to_unit))) /. snd(convert_time ((snd(from_unit)), 1.) (snd(to_unit)))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, b_val +. snd(convert_speed a b_unit)) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> true | Leaf :: tl -> sum_ tl acc | Branch (width, subtree) :: tl -> ( if width *. width > acc then false else sum_ tl (acc -. width *. width) ) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> (if...
let failure () = failwith "Wrong Input Type" ;;
let mode (l: 'a list) : 'a = match l with | [] -> failure () | _ -> let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = if (List.length (List.tl l) != 0) then let filtered = (List.filter (fun x -> x = List.hd l) l) in if List.length filtered > max_num then aux (List.filter (fun x -> x != List....
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failure () | _ -> let rec aux l newlist = if (List.length (List.tl l) != 1) then aux (List.tl l) ((List.hd l, List.nth l 1) :: newlist) else mode newlist in aux l empty ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (match to_unit with | Second -> (Second, val_) | Hour -> (Hour, val_ /. 3600.) ) | Hour -> (match to_unit with | Hour -> (Hour, val_) | Second -> (Second, val_ *. 3600.)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> (match to_unit with | Foot -> (Foot, val_) | Meter -> (Meter, val_ *. 0.3048) | Mile -> (Mile, val_ /. 5280.) ) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Meter -> (Meter, val_) | Mil...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (((fst to_unit), (snd to_unit)), snd (convert_dist (fst from_unit, val_) (fst to_unit)) /. snd (convert_time (snd from_unit, 1.) (snd to_unit))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (((fst b_unit),(snd b_unit)), b_val +. snd (convert_speed a b_unit)) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf ::tl -> sum_ tl acc | Branch (width, subtree) :: tl -> sum_ tl (acc +. width *. width) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> ( if not ((check subtree) && (sum_ subtree 0. <= ...
let mode (l: 'a list) : 'a = let l = List.sort compare l in let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el; | x :: xs -> if x = cur_el then if cur_num+1 > max_num then aux xs (cur_el, cur_num+1) (cur_el, cur_num+1) else aux xs (cur_el, cur_num+1) (max_el, max_n...
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (l: 'a list) (tuple_list: ('a * 'a) list ) = match l with |[] -> tuple_list |_ :: [] -> tuple_list |x::xs -> (x, List.hd xs):: aux xs tuple_list in mode (aux l []) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Hour -> (match to_unit with | Second -> (Second, val_ *. 3600.) | Hour -> (Hour, val_)) | Second -> (match to_unit with |Second -> (Second, val_) |Hour -> (Hour, val_ /. 3600.)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with |Foot -> (match to_unit with |Meter -> (Meter, val_ *. 0.3048) |Mile -> (Mile, val_ /. 5280.) |Foot -> (Foot, val_)) | Meter -> (match to_unit with |Meter -> (Meter, val_) |Mile -> (Mile, val_ /. 1609.344) |Foot -> (...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (unit_dist, unit_time) = from_unit in let (to_dist, to_time) = to_unit in let (new_dist, newval_) = convert_dist(unit_dist, val_) to_dist in let (new_time, newerval_) = convert_time(to_time, newval_) unit_time in (new_dist, new_ti...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (dist_unit, time_unit) = speed_unit in let (real_time_unit, real_time_val) = time in let (newspeed_unit, newspeedvalue) = convert_speed ((dist_unit, time_unit), speed_val) (dist_unit, real_time_unit) in let (good_dist, good_time...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | hd :: tl -> (if hd = cur_el then aux tl (cur_el, cur_num + 1) (max_el, max_num) else (if cur_num > max_num then aux tl (hd, 1) (cur_el, cur_num) ...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Input list is empty" | x :: [] -> failwith "Input list has only one element" | _ -> (let (_ :: l1) = l in let (_ :: l2_rev) = List.rev l in let l2 = List.rev l2_rev in mode (List.combine l2 l1)) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (match to_unit with | Second -> (Second, val_) | Hour -> (Hour, val_ /. 3600.)) | Hour -> (match to_unit with | Second -> (Second, val_ *. 3600.) | Hour -> (Hour, val_)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> (match to_unit with | Foot -> (Foot, val_) | Meter -> (Meter, val_ *. 0.3048) | Mile -> (Mile, val_ /. 5280.)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Meter -> (Meter, val_) | Mile...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let numer = snd (convert_dist (fst from_unit, 1.) (fst to_unit)) in let denom = snd (convert_time (snd from_unit, 1.) (snd to_unit)) in (to_unit, val_ *. numer /. denom) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (a_unit, a_val) = convert_speed a b_unit in (b_unit, a_val +. b_val) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch (width, subtree) :: tl -> sum_ tl (acc +. width**2.) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> (if ((check subtree) && ((sum_ subtree 0.) <= width *...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if (cur_num > max_num) then cur_el else max_el | h :: xs -> ( if h = cur_el then aux xs (cur_el , cur_num + 1) (max_el, max_num) else (if cur_num > max_num then aux xs (h , 1) (cur_el, cur_num...
let pair_mode (l: 'a list) : 'a * 'a = let rec make_list l1 l2 = match l1 with |[] -> l2 | x :: xs -> match xs with |[] -> l2 | y :: ys -> make_list xs ((x,y) :: l2) in let l2 = make_list l [] in mode l2 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if (val_ < 0.0) then failwith "No negative number" else match from_unit with | Hour -> if(to_unit = Second) then (Second ,(val_ *. 3600.)) else (Hour,val_ ) | Second -> if(to_unit = Hour) then (Hour,(val_ /. 3600.)) else (Second, val_) ;...
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if (val_ < 0.0) then failwith "No negative number" else let meter_mile = 0.3048 *. 5280. in match from_unit with |Foot -> if ( to_unit = Mile) then (Mile , val_ /. 5280.) else (if (to_unit = Meter) then (Meter, val_ *.0.3048) else (Foot,...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ( _ ,dist) = convert_dist (fst from_unit, val_) (fst to_unit) in let ( _ , time) = convert_time (snd from_unit, 1.) (snd to_unit) in (to_unit, dist /. time) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_val = convert_speed a b_unit in (b_unit, snd a_val +. b_val) ;;
let passes_da_vinci t = let rec check t = match t with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> ( width *. width >= sum_square (subtree)) && check subtree && check tl in check [t] ;;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with |[] -> (match cur_num > max_num with | true -> cur_el | _ -> max_el ) |_ -> (match ((cur_el = (List.hd l)),(cur_num + 1) > max_num) with | true,false -> aux (List.tl l) ((List.hd l),cur_num+1)(max_el,...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Undefined input." | _ -> let cl = c_list l [] 0 ((List.length l) - 1) in let el = mode cl in (List.nth el 0,List.nth el 1) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | Second,Hour -> (Hour, (val_ /. 3600.)) | Hour,Second -> (Second, (val_ *. 3600.)) | Second,Second -> (Second, val_) | Hour,Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot ->(match to_unit with | Meter -> (Meter, (val_ *. 0.3048)) | Mile -> (Mile, (val_ /. 5280.)) | _ -> (Foot, val_)) | Meter ->(match to_unit with | Foot -> (Foot, (val_ /. 0.3048)) | Mile -> (Mile, (val_ /. 0.30...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist = convert_dist ((fst from_unit), (val_)) (fst to_unit) in let time = convert_time ((snd from_unit), (1.)) (snd to_unit) in (to_unit, ((snd dist) /. (snd time))) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let timeA = convert_time ((fst time), (snd time)) (snd speed_unit) in ((fst speed_unit), ((snd timeA) *. speed_val)) ;; let rec list_sqrsum (nodes: tree list) : float = match nodes with | [] -> 0. | x :: xs -> match x with | Branch(...
let mode (l: 'a list) : 'a = if l = [] then failwith "Error: Empty:" else let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with |[] when cur_num > max_num -> cur_el |[] -> max_el |x::xs when x = cur_el -> aux (List.tl l) (cur_el, cur_num + 1) (max_el, max_num) |x::xs when cur_num > ...
let pair_mode (l: 'a list) : 'a * 'a = let l1 = List.tl l in let l2 = List.rev(List.tl(List.rev l)) in let l3 = List.combine l2 l1 in mode l3 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with |(Second, Hour) -> (Hour, val_ /. 3600.) |(Hour, Second) -> (Second, val_ *. 3600.) |(Hour, Hour) | (Second, Second) -> (from_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with |(Foot, Foot) | (Mile, Mile) | (Meter, Meter) -> (from_unit, val_) |(Foot,Meter) -> (Meter, val_ *. 0.3048) |(Foot, Mile) ->(Mile, val_ *. (1./.5280.)) |(Meter, Foot) ->(Foot, val_ *. (1. /. 0.3048)) |(Met...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distance = fst(from_unit) in let time = snd(from_unit) in let numer = convert_dist (distance, val_) (fst(to_unit)) in let denom = convert_time (time, 1.) (snd(to_unit)) in (to_unit, snd(numer) /. snd(denom)) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let var = convert_speed (fst(a), snd(a)) b_unit in (b_unit, snd(var) +. b_val) ;;
let passes_da_vinci t = let rec sum_ l w = match l with |[] -> true |Leaf :: tl -> true |Branch(width, subtree) :: tl -> true in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> true in check [t] ;;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | h::t -> if compare h cur_el = 0 then if (succ cur_num) > max_num then aux t (h, succ cur_num) (h, succ cur_num) else aux t (h, succ cur_num) (max_el, max_num) else aux t (h, 1) (max_e...
let pair_mode (l: 'a list) : 'a * 'a = let rec aux l1 l2 prev = match l1 with | [] -> l2 | h::t -> aux t ((prev, h)::l2) h in aux (List.tl l) [] (List.hd l) |> mode ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let from_to = (from_unit, to_unit) in match from_to with | (Second, Hour) -> (Hour, val_ /. 3600.0) | (Hour, Second) -> (Second, val_ *. 3600.0) | (Hour, Hour) -> (Hour, val_) | (Second, Second) -> (Second, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let from_to = (from_unit, to_unit) in match from_to with | (Foot, Foot) -> (Foot, val_) | (Meter, Meter) -> (Meter, val_) | (Mile, Mile) -> (Mile, val_) | (Foot, Meter) -> (Meter, 0.3048 *. val_) | (Meter, Foot) -> (Foot, val_ /. 0.3048)...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist, from_time), (to_dist, to_time)) = (from_unit, to_unit) in let c_dist = convert_dist (from_dist, val_) to_dist in let c_time = convert_time (to_time, snd c_dist) from_time in ((to_dist, to_time), snd c_time) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let c_t = snd speed_unit |> convert_time time in (fst speed_unit, snd c_t *. speed_val) ;; let sums_tlis tlis = let f x y = match y with | Leaf -> x | Branch (val_, _) -> x +. val_ *. val_ in List.fold_left f 0. tlis ;; let rec pass...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | x :: xs -> if cur_el = x then aux xs (x, (cur_num+1)) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1) (cur_el, cur_num) else aux x...
let pair_mode (l: 'a list) : 'a * 'a = let help123 (li: 'a list) : 'b list = if List.length(li) < 2 then failwith "list cannot be empty or with 1 element" else let helper1 (l1: 'a list): 'a list = let hd::tl = l1 in tl in let s1 = helper1 li in let s2 = List.rev li in let s3 = helper1 s2 in let s4 = List.rev s3 in List...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> if from_unit = Second then (Second, val_) else (Second,(val_ *. 3600.)) | Hour -> if from_unit = Hour then (Hour, val_) else (Hour, (val_ /. 3600.)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> if from_unit = Foot then (Foot, val_) else if from_unit = Meter then (Meter, (val_ /. 0.3048)) else (Mile, (val_ *. 5280.)) | Meter -> if from_unit = Foot then (Foot, (val_ *. 0.3048)) else if from_unit = Met...