text
stringlengths
0
601k
let pair_mode (l: 'a list) : 'a * 'a = match l with |[]->failwith "Empty list" |hd::[]->failwith "Only 1 element" |_ -> mode (List.combine (List.rev (List.tl (List.rev l))) (List.tl l)) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with |(Hour,Second)->(to_unit, val_ *. 3600.) |(Second,Hour)->(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) |(Foot,Mile)-> (to_unit, val_ /. 5280. ) |(Meter,Foot)-> (to_unit, val_ /. 0.3048) |(Meter,Mile)-> (to_unit, val_ /. 0.3048 /. 5280.) |(Mile,Foot)-> (to_unit, val_ *. 5280.) |(Mile,Meter)-> (to_unit, val_ *. 5280. *. 0.3048) |_ -> (to_unit, val_) ;;
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, snd(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 -> check tl |Branch(width,subtree)::tl-> if ((check subtree)&&((sum_ subtree 0.)<=(width**2.))) then check tl else false 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 | x:: xs -> if (x <> cur_el) then aux xs (x, 1) (max_el, max_num) else if (x = cur_el && cur_num+ 1 > max_num) then aux xs (x, cur_num+ 1) (x, cur_num+ 1) else aux xs (x, cur_num+ 1) (max_el, max_num) in match l with |[] -> notimplemented () |_ -> let l0 = List.sort compare l in aux l0 (List.hd l0, 0) (List.hd l0, 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> notimplemented () | _:: l0 -> match l0 with |[] -> notimplemented () |_ -> match (List.rev l) with |[] -> notimplemented () | _:: l3 -> let l2= List.rev l3 in let aList= List.combine l2 l0 in mode aList ;;
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.) | u, _ -> (u, 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.) | Foot, Meter -> (Meter, val_ *. 0.3048) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. (0.3048 *. 5280.)) | Mile, Foot -> (Foot, val_ *. 5280.) | Mile, Meter -> (Meter, val_ *. 5280. *. 0.3048) | u, _ -> (u, val_) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d1, t1), (d2, t2)= from_unit, to_unit in let (_, dis)= convert_dist (d1, 1.) d2 in let (_, tim)= convert_time (t1, 1.) t2 in ((d2, t2), val_ *. dis /. tim) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (du0, tu0)= speed_unit in let (_, tv1)= convert_time time tu0 in (du0, tv1 *. speed_val) ;; let rec sumTreeList trList= match trList with | [] -> 0. | x:: xs -> match x with | Leaf -> sumTreeList xs | Branch (f, _) -> f *.f +. sumTreeList xs;; let rec passes_da_vinci t = let rec helper trList= match trList with | [] -> true | x:: xs -> (passes_da_vinci x) && (helper xs) in match t with | Leaf -> true | Branch (f, l) -> ((sumTreeList l)<= f*.f) && (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 | [] -> max_el | x:: xs -> if (x <> cur_el) then aux xs (x, 1) (max_el, max_num) else if (x = cur_el && cur_num+ 1 > max_num) then aux xs (x, cur_num+ 1) (x, cur_num+ 1) else aux xs (x, cur_num+ 1) (max_el, max_num) in match l with |[] -> notimplemented () |_ -> let l0 = List.sort compare l in aux l0 (List.hd l0, 0) (List.hd l0, 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> notimplemented () | _:: l0 -> match l0 with |[] -> notimplemented () |_ -> match (List.rev l) with |[] -> notimplemented () | _:: l3 -> let l2= List.rev l3 in let aList= List.combine l2 l0 in mode aList ;;
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.) | u, _ -> (u, 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.) | Foot, Meter -> (Meter, val_ *. 0.3048) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. (0.3048 *. 5280.)) | Mile, Foot -> (Foot, val_ *. 5280.) | Mile, Meter -> (Meter, val_ *. 5280. *. 0.3048) | u, _ -> (u, val_) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d1, t1), (d2, t2)= from_unit, to_unit in let (_, dis)= convert_dist (d1, 1.) d2 in let (_, tim)= convert_time (t1, 1.) t2 in ((d2, t2), val_ *. dis /. tim) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (du0, tu0)= speed_unit in let (_, tv1)= convert_time time tu0 in (du0, tv1 *. speed_val) ;; let rec sumTreeList trList= match trList with | [] -> 0. | x:: xs -> match x with | Leaf -> sumTreeList xs | Branch (f, _) -> f *.f +. sumTreeList xs;; let rec passes_da_vinci t = let rec helper trList= match trList with | [] -> true | x:: xs -> (passes_da_vinci x) && (helper xs) in match t with | Leaf -> true | Branch (f, l) -> ((sumTreeList l)<= f*.f) && (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 cur_num > max_num then cur_el else max_el | x::xs -> if cur_el = x then aux xs (cur_el, (cur_num+1)) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1) (cur_el, cur_num) else aux xs (x, 1) (max_el, max_num) in match List.sort compare l with | [] -> failwith "Please enter a non-empty list!" | x::xs -> aux xs (x, 1) (x, 0) ;;
let pair_mode (l: 'a list) : 'a * 'a = let l1 = l in let l2 = List.rev l in let helper (l: 'a list) : 'a list= match l with | x::xs -> xs | _ -> failwith "Please enter a valid list" in let l1 = helper l1 in let l2 = List.rev (helper l2) in mode (List.combine l2 l1) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if fst(from_unit,val_) = to_unit then (from_unit,val_) else match fst (from_unit, val_) with | Hour -> (Second, (val_ *. 3600.)) | Second -> (Hour, (val_ /. 3600.)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if fst(from_unit,val_) = to_unit then (from_unit,val_) else match fst (from_unit, val_) with | Foot -> ( match to_unit with | Meter -> (Meter, val_ *. 0.3048) | Mile -> (Mile, val_ /. 5280.) ) | Meter -> ( match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Mile -> (Mile, val_ /. 5280. /. 0.3048) ) | Mile -> ( match to_unit with | Meter -> (Meter, val_ *. 5280. *. 0.3048) | Foot -> (Foot, val_ *. 5280.) ) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let middle = convert_dist ((fst(from_unit)), val_) (fst(to_unit)) in let finish = convert_time ((snd(from_unit)), 1. /. (snd(middle))) (snd(to_unit)) in (to_unit, (1. /. snd(finish))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let middle = convert_speed a b_unit in (b_unit, (snd(middle)) +. b_val) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | Branch (width, subtree) :: xs -> (sum_ xs acc +. width *. width) | Leaf :: xs -> sum_ xs acc | _ -> acc in let rec check l = match l with |[] -> true |Branch (width, subtree)::xs -> if width *. width < sum_ subtree 0. then false else (if not (check subtree) then false else check xs) | Leaf::xs -> check xs in check [t] ;;
let rec mode (l: 'a list) : 'a = let list = List.sort compare (l : 'a list) in match list with |[] -> failwith "List is empty" |hd::t -> let rec aux list ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match list with |[] -> if cur_num > max_num then cur_el else max_el |x::xs when x = cur_el -> if cur_num + 1 > max_num then aux xs (x, cur_num + 1) (x, cur_num + 1) else if cur_num + 1 = max_num then if x <= max_el then aux xs (x, cur_num + 1) (x, cur_num + 1) else aux xs (x, cur_num + 1) (max_el, max_num) else aux xs (x, cur_num + 1) (max_el, max_num) |y ::xs -> if max_num = cur_num then if y < max_el then aux xs (y, 1) (y, 1) else aux xs (y, 1) (max_el, max_num) else aux xs (y, 1) (max_el, max_num) in aux t (hd,1) (hd, 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "List is empty" | _::[] -> failwith "Not enough elements" | _::t -> let l1 = List.tl l in let l2 = List.rev ( List.tl (List.rev l)) in let list = List.combine l2 l1 in mode list ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match fst(from_unit, val_) with | Second -> (match to_unit with |Second -> (to_unit, snd(from_unit, val_)) |Hour -> (to_unit, (snd(from_unit, val_) /. 3600.0) ) ) | Hour -> (match to_unit with |Hour -> (to_unit, snd(from_unit, val_)) |Second -> (to_unit, (snd(from_unit, val_) *. 3600.0)) ) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match fst(from_unit, val_) with | Foot -> (match to_unit with |Foot -> (to_unit, snd(from_unit, val_)) |Meter -> (to_unit, snd(from_unit, val_) *. 0.3048) |Mile -> (to_unit, snd(from_unit, val_) /. 5280.0) ) | Meter -> (match to_unit with |Meter -> (to_unit, snd(from_unit, val_)) |Mile -> (to_unit, snd(from_unit, val_) /. 0.3048 /. 5280.0 ) |Foot -> (to_unit, snd(from_unit, val_) /. 0.3048) ) | Mile -> (match to_unit with |Mile -> (to_unit, snd(from_unit, val_)) |Meter -> (to_unit, snd(from_unit, val_) *. 5280.0 *. 0.3048) |Foot -> (to_unit, snd(from_unit, val_) *. 5280.0) ) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distanceFrom = fst(fst(from_unit, val_)) in let timeFrom = snd(fst(from_unit, val_)) in let distanceTo = fst(to_unit) in let timeTo = snd(to_unit) in let value = snd(from_unit, val_) in let newValue = snd((convert_dist (distanceFrom, value) distanceTo)) /. snd(convert_time (timeFrom, 1.) timeTo) in ((distanceTo, timeTo), newValue) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed = fst(speed_unit, speed_val) in let desiredUnit = fst(speed) in let desiredTime = snd(speed) in let correctTime = convert_time time desiredTime in let distanceTravelled = snd(speed_unit, speed_val) *. snd(correctTime) in (desiredUnit, distanceTravelled) ;; let rec passes_da_vinci t = notimplemented () ;;
let rec mode (l: 'a list) : 'a = let list = List.sort compare (l : 'a list) in match list with |[] -> failwith "List is empty" |hd::t -> let rec aux list ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match list with |[] -> if cur_num > max_num then cur_el else max_el |x::xs when x = cur_el -> if cur_num + 1 > max_num then aux xs (x, cur_num + 1) (x, cur_num + 1) else if cur_num + 1 = max_num then if x <= max_el then aux xs (x, cur_num + 1) (x, cur_num + 1) else aux xs (x, cur_num + 1) (max_el, max_num) else aux xs (x, cur_num + 1) (max_el, max_num) |y ::xs -> if max_num = cur_num then if y < max_el then aux xs (y, 1) (y, 1) else aux xs (y, 1) (max_el, max_num) else aux xs (y, 1) (max_el, max_num) in aux t (hd,1) (hd, 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "List is empty" | _::[] -> failwith "Not enough elements" | _::t -> let l1 = List.tl l in let l2 = List.rev ( List.tl (List.rev l)) in let list = List.combine l2 l1 in mode list ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match fst(from_unit, val_) with | Second -> (match to_unit with |Second -> (to_unit, snd(from_unit, val_)) |Hour -> (to_unit, (snd(from_unit, val_) /. 3600.0) ) ) | Hour -> (match to_unit with |Hour -> (to_unit, snd(from_unit, val_)) |Second -> (to_unit, (snd(from_unit, val_) *. 3600.0)) ) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match fst(from_unit, val_) with | Foot -> (match to_unit with |Foot -> (to_unit, snd(from_unit, val_)) |Meter -> (to_unit, snd(from_unit, val_) *. 0.3048) |Mile -> (to_unit, snd(from_unit, val_) /. 5280.0) ) | Meter -> (match to_unit with |Meter -> (to_unit, snd(from_unit, val_)) |Mile -> (to_unit, snd(from_unit, val_) /. 0.3048 /. 5280.0 ) |Foot -> (to_unit, snd(from_unit, val_) /. 0.3048) ) | Mile -> (match to_unit with |Mile -> (to_unit, snd(from_unit, val_)) |Meter -> (to_unit, snd(from_unit, val_) *. 5280.0 *. 0.3048) |Foot -> (to_unit, snd(from_unit, val_) *. 5280.0) ) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distanceFrom = fst(fst(from_unit, val_)) in let timeFrom = snd(fst(from_unit, val_)) in let distanceTo = fst(to_unit) in let timeTo = snd(to_unit) in let value = snd(from_unit, val_) in let newValue = snd((convert_dist (distanceFrom, value) distanceTo)) /. snd(convert_time (timeFrom, 1.) timeTo) in ((distanceTo, timeTo), newValue) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed = fst(speed_unit, speed_val) in let desiredUnit = fst(speed) in let desiredTime = snd(speed) in let correctTime = convert_time time desiredTime in let distanceTravelled = snd(speed_unit, speed_val) *. snd(correctTime) in (desiredUnit, distanceTravelled) ;; let rec passes_da_vinci t = notimplemented () ;;
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 | h :: t -> if h = cur_el then if h = max_el then aux t ((cur_el, (cur_num+1)) : 'a * int) ((max_el, (max_num+1)) : 'a * int) else if ((cur_num+1)>max_num) then aux t ((cur_el, (cur_num+1)) : 'a * int) ((cur_el, cur_num+1) : 'a * int) else aux t ((cur_el, (cur_num+1)) : 'a * int) ((max_el, max_num) : 'a * int) else if (max_num>0) then aux t ((h, 1) : 'a * int) ((max_el, max_num) : 'a * int) else aux t ((h, 1) : 'a * int) ((h, 1) : 'a * int) in match l with | [] -> failwith "empty list" | h :: t -> aux l ((h, 0) : 'a * int) ((h, 0) : 'a * int) ;;
let pair_mode (l: 'a list) : ('a * 'a) = match l with | [] -> failwith "list too short" | h :: [] -> failwith "list too short" | _ -> let rec removelast (l: 'a list) (l2: 'a list): ('a list) = match l with | [] -> failwith "error" | h :: [] -> List.rev l2 | h :: t -> removelast t (h::l2) in let list_no_last = removelast l [] in let list_no_first = List.tl l in let pair_list = List.combine list_no_last list_no_first in mode pair_list;;
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)) | (Foot, Mile) -> (to_unit, (val_ /. 5280.)) | (Mile, Foot) -> (to_unit, (val_ *. 5280.)) | (Mile, Meter) -> (to_unit, (val_ *. 5280. *. 0.3048)) | (Meter, Foot) -> (to_unit, (val_ /. 0.3048)) | (Meter, Mile) -> (to_unit, (val_ /. 0.3048 /. 5280.)) | _ -> (to_unit, val_) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_dist_unit, from_time_unit) = from_unit in let (to_dist_unit, to_time_unit) = to_unit in let (dist_unit, value1) = (convert_dist (from_dist_unit, val_) to_dist_unit) in let (time_unit, value2) = (convert_time (from_time_unit, 1.) to_time_unit ) in (to_unit, (value1 /. value2)) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (arg1_speed, arg1_val) = convert_speed a b_unit in (b_unit, (arg1_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 *. 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. <= (width *. width)))) then false else 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 | [] -> if cur_num > max_num then cur_el else max_el | e::t -> if cur_el = e then aux t (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux t (e,1) (cur_el, cur_num) else aux t (e,1) (max_el,max_num) in let y = List.sort compare l in match y with |[] -> failwith "list is empty" |e::[] -> e |e::t -> (aux y (e,1) (e,0)) ;;
let pair_mode (l: 'a list) : 'a * 'a = let rec bilist l = match l with |[] -> failwith "list is empty" |e::[] -> [] |e::r::t -> [(e,r)]@(bilist (r::t)) in mode (bilist l) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with |Second -> if to_unit = from_unit then (Second, val_) else (Hour, val_ /. 3600. ) |Hour -> if to_unit = from_unit then (Hour, val_) else (Second, val_ *. 3600.) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with |Foot -> if to_unit = from_unit then (Foot, val_) else if to_unit = Meter then (Meter, val_ *. 0.3048) else (Mile, val_ /. 5280.) |Meter -> if to_unit = from_unit then (Meter, val_) else if to_unit = Foot then (Foot, val_ /. 0.3048) else (Mile, (val_ /. 0.3048) /. 5280.) |Mile -> if to_unit = from_unit then (Mile, val_) else if to_unit = Foot then (Foot, val_ *. 5280.) else (Meter, (val_ *. 5280.) *. 0.3048) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit with |(Foot, Second) -> if to_unit = from_unit then ((Foot,Second),val_) else if to_unit = (Foot, Hour) then ((Foot, Hour), val_ *. 3600.) else if to_unit = (Meter, Second) then ((Meter, Second), val_ *. 0.3048) else if to_unit = (Meter, Hour) then ((Meter, Hour), (val_ *. 0.3048)*.3600.) else if to_unit = (Mile, Second) then ((Mile, Second), (val_ /. 5280.)) else ((Mile, Hour), ((val_ /. 5280.)*.3600.)) |(Foot, Hour) -> if to_unit = from_unit then ((Foot,Hour),val_) else if to_unit = (Foot, Second) then ((Foot, Hour), val_ /. 3600.) else if to_unit = (Meter, Second) then ((Meter, Second), (val_ *. 0.3048)/.3600.) else if to_unit = (Meter, Hour) then ((Meter, Hour), (val_ *. 0.3048)) else if to_unit = (Mile, Second) then ((Mile, Second), (val_ /. 5280.)/.3600.) else ((Mile, Hour), (val_ /. 5280.)) |(Meter, Second) -> if to_unit = from_unit then ((Meter,Second),val_) else if to_unit = (Foot, Second) then ((Foot, Second), val_ /. 0.3048) else if to_unit = (Foot, Hour) then ((Foot, Hour), (val_ /. 0.3048) *.3600.) else if to_unit = (Meter, Hour) then ((Meter, Hour), (val_ *. 3600.)) else if to_unit = (Mile, Second) then ((Mile, Second), ((val_ /. 0.3048) /. 5280.)) else ((Mile, Hour), (((val_ /. 0.3048) /. 5280.)*.3600.)) |(Meter, Hour) -> if to_unit = from_unit then ((Meter, Hour),val_) else if to_unit = (Foot, Second) then ((Foot, Second), (val_ /. 0.3048)/.3600.) else if to_unit = (Foot, Hour) then ((Foot, Hour), (val_ /. 0.3048)) else if to_unit = (Meter, Second) then ((Meter, Second), (val_ /. 3600.)) else if to_unit = (Mile, Second) then ((Mile, Second), ((val_ /. 0.3048) /. 5280.)/.3600.) else ((Mile, Hour), (((val_ /. 0.3048) /. 5280.))) |(Mile, Second) -> if to_unit = from_unit then ((Mile,Second),val_) else if to_unit = (Foot, Second) then ((Foot, Second), (val_ *. 5280.)) else if to_unit = (Foot, Hour) then ((Foot, Hour), (val_ *. 5280.) *.3600.) else if to_unit = (Meter, Second) then ((Meter, Second), (((val_ *. 5280.)*. 0.3048))) else if to_unit = (Meter, Hour) then ((Meter, Hour), (((val_ *. 5280.)*. 0.3048)*.3600.)) else ((Mile, Hour), ((val_ *.3600.))) |(Mile, Hour) -> if to_unit = from_unit then ((Mile,Hour),val_) else if to_unit = (Foot, Second) then ((Foot, Second), (val_ *. 5280.)/. 3600.) else if to_unit = (Foot, Hour) then ((Foot, Hour), (val_ *. 5280.)) else if to_unit = (Meter, Second) then ((Meter, Second), (((val_ *. 5280.)*. 0.3048)/.3600.)) else if to_unit = (Meter, Hour) then ((Meter, Hour), (((val_ *. 5280.)*. 0.3048))) else ((Mile, Second), ((val_ /.3600.))) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let gethim (a,_) = a in let gethimm (_,a) = a in let u = gethim speed_unit in let p = gethim time in let z = gethimm speed_unit in if p = z then let (r,t) = time in (u, (t *. speed_val)) else begin let b = convert_time time z in let (r,t) = b in (u, (t *. speed_val)) end ;; let rec passes_da_vinci t = let rec sqrr f e = match f with |[] -> e |Leaf::v -> sqrr v e |Branch (r,t)::v -> sqrr v (((r*.r) +. e)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not (check subtree) then false else if (sqrr subtree 0.) > (width *. width) then false else 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 | [] -> if cur_num > max_num then cur_el else max_el | x :: xs -> if (compare x cur_el = 0 && cur_num + 1 > max_num) then aux xs (x, cur_num) (cur_el, cur_num + 1) else if compare x cur_el = 0 then aux xs (x, cur_num+1) (max_el, max_num) else if max_num = 0 then aux xs (x, 1) (x, 1) else aux xs (x, 1) (max_el, max_num) in match l with | [] -> failwith "This function does not take empty lists as input." | x :: xs -> aux (List.sort compare l) (x, 0) (x, 0) ;;
let pair_mode (l: 'a list) : 'a * 'a = if l == [] then failwith "This function does not take empty lists as input." else let l1 = List.tl (l) and l2 = List.rev (List.tl (List.rev l)) in let pairs = List.combine l2 l1 in mode pairs ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> if from_unit = Hour then (Second, (val_ *. 3600.0)) else (Second, val_ ) | Hour -> if from_unit = Second then (Hour, (val_ /. 3600.0)) else (Hour, val_ ) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> if from_unit = Meter then (Foot, (val_ /. 0.3048)) else if from_unit = Mile then (Mile, (val_ *. 5280.0)) else (from_unit, val_) | Meter -> if from_unit = Foot then (Meter, val_ *. 0.3048) else if from_unit = Mile then (Meter, (val_ *. (0.3048 *. 5280.0))) else (from_unit, val_) | Mile -> if from_unit = Foot then (Mile, (val_ /. 5280.0)) else if from_unit = Meter then (Mile, (val_ /. (0.3048 *. 5280.0))) else (from_unit, val_) ;;
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.0) (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: tree list) : float = match l with | Leaf :: tl -> 0. +. sum_ tl | [] -> 0. | Branch (x, y) :: tl -> (x *. x) +. sum_ tl in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> if not ((check subtree) && (sum_ subtree <= (width *. width))) then false else check tl in check [t] ;;
let error() = failwith "Incompatible list length";;
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 h= cur_el then if (cur_num + 1) > max_num then aux t (h, (cur_num + 1)) (cur_el, (cur_num + 1)) else aux t (h, (cur_num + 1)) (max_el, max_num) else aux t (h, 1) (max_el, max_num) in let l = List.sort compare l in match l with |[] -> error() |h::t -> aux t (h, 1) (h, 1) ;;
let pair_mode l = let rec aux l pairs = match l with |_::[] -> pairs |h::m::t-> aux (m::t) ((h,m) :: pairs) in match l with |[] -> error() |[_] -> error() | _ -> mode(aux l []) ;; let secInHour = 3600.;;
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_ /. secInHour)) |Hour, Second -> (to_unit, (val_ *. secInHour)) |_,_ -> (to_unit, val_) ;; let metersInFoot = 0.3048 let feetInMile = 5280.;;
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_ *. metersInFoot)) |Foot,Mile -> (to_unit, (val_ /. feetInMile)) |Meter,Foot -> (to_unit, (val_ /. metersInFoot)) |Meter,Mile -> (to_unit, (val_ /. metersInFoot /. feetInMile)) |Mile,Foot -> (to_unit, (val_ *. feetInMile)) |Mile,Meter -> (to_unit, (val_ *. metersInFoot *. feetInMile )) | _,_ -> (to_unit, val_) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist,t),(dist',t') = from_unit, to_unit in let (_,convertedDist) = convert_dist (dist, val_) dist' in let (_,convertedTime) = convert_time (t, 1.) t' in (to_unit, convertedDist /. convertedTime) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (d,t') = speed_unit in let (_, convertedTime) = convert_time time t' in (d,convertedTime *. speed_val) ;; let rec sumOfSquares list = match list with |[] -> 0. |Leaf::t -> 0. +. sumOfSquares t |Branch(diameter,_)::t -> diameter*.diameter +. sumOfSquares t ;; let rec passes_da_vinci t = match t with |Leaf -> true |Branch(d, trees) -> let sum = sumOfSquares trees in if d *. d < sum then false else match trees with |[] -> true |h::_ -> passes_da_vinci h ;;
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::t -> if h = cur_el then aux t (cur_el, cur_num + 1) (max_el, max_num) else let (new_max_el, new_max_num) = if cur_num > max_num then (cur_el, cur_num) else (max_el, max_num) in aux t (h, 1) (new_max_el, new_max_num) in let sorted = (List.sort compare l) in aux (List.tl sorted) (List.hd sorted, 1) (List.hd sorted, 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = let rec get_bigram l = match l with | h1 :: h2 :: t -> (h1, h2) :: (get_bigram (h2::t)) | _ -> [] in mode (get_bigram l) ;;
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.0) | (Hour, Second) -> (to_unit, val_ *. 3600.0) | _ -> (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, 0.3048 *. val_) | (Foot, Mile) -> (to_unit, val_ /. 5280.0) | (Meter, Foot) -> (to_unit, val_ /. 0.3048) | (Meter, Mile) -> (to_unit, val_ /. 0.3048 /. 5280.0) | (Mile, Foot) -> (to_unit, val_ *. 5280.0) | (Mile, Meter) -> (to_unit, val_ *. 5280.0 *. 0.3048) | _ -> (to_unit, val_) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_unit_dist, from_unit_time), (to_unit_dist, to_unit_time)) = (from_unit, to_unit) in let (_, dis_val) = convert_dist (from_unit_dist, val_) to_unit_dist in let (_, time_val) = convert_time (from_unit_time, 1.0) to_unit_time in (to_unit, dis_val /. time_val) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let ((s_dis_unit, s_time_unit), (t_unit, t_val)) = (speed_unit, time) in let (_, new_speed) = convert_speed (speed_unit, speed_val) (s_dis_unit, t_unit) in (s_dis_unit, new_speed *. t_val) ;; let tree_example2 = Branch (4., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (4., []) ]) ;; let rec passes_da_vinci t = let get_width t = match t with | Leaf -> 0.0 | Branch (w, _) -> w in let get_childs t = match t with | Leaf -> [] | Branch (_, bs) -> bs in let rec compute_sum_square ts = match ts with | [] -> 0.0 | h::t -> let w = get_width h in (w *. w) +. (compute_sum_square t) in let rec check_all ts = match ts with | [] -> true | h::t -> (passes_da_vinci h) && (check_all (get_childs h)) && (check_all t) in let w = get_width t in let children = get_childs t in ((compute_sum_square children) <= (w *. w)) && (check_all children) ;;
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 x = cur_el && cur_num+1<= max_num then aux xs (x,cur_num+1) (max_el,max_num) else if x= cur_el &&cur_num+1>max_num then aux xs (x,cur_num+1) (x, max_num+1) else aux xs (x,1) (max_el,max_num) in match (List.sort compare l) with |[]-> failwith "empty list" |x::xs-> aux (List.sort compare xs) (x,1) (x,1) ;;
let pair_mode (l: 'a list) : 'a * 'a = let rec copy list1 list2= match list1 with |[]->list2 |x::xs->x::(copy xs list2) in let cut list = match list with |[]->list |x::xs->xs in let list1=[] in let list1=copy l list1 in let new_1=cut list1 in let list2= [] in let list2= copy l list2 in let rev_list2 = List.rev list2 in let cut_list2= cut rev_list2 in let new_2=List.rev cut_list2 in let new_input =List.combine new_2 new_1 in let new_input = List.sort compare new_input in mode new_input ;;
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, (3600.*. val_)) |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 (Foot, val_/.0.3048) else (Foot,val_*.5280. ) |Meter->if from_unit = Meter then (Meter,val_) else if from_unit=Foot then (Meter,val_*.0.3048) else (Meter,val_*.5280.*.0.3048) |Mile->if from_unit=Mile then (Mile,val_ )else if from_unit=Foot then (Mile,val_/.5280.) else (Mile,val_/.0.3048/.5280.) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match to_unit with |(Foot,Second)-> if from_unit=(Foot,Hour) then ((Foot,Second),val_/.3600.) else if from_unit = (Meter,Second) then ((Foot,Second),snd(convert_dist (Meter,val_) Foot)) else if from_unit =( Meter,Hour) then ((Foot,Second),snd(convert_dist (Meter,val_) Foot)/.3600.) else if from_unit =(Mile,Second) then ((Foot,Second),snd(convert_dist (Mile,val_) Foot)) else if from_unit = (Mile,Hour) then ((Foot,Second),snd(convert_dist (Mile,val_)Foot)/.3600. ) else ((Foot,Second),val_) |(Foot,Hour)-> if from_unit = (Foot,Second) then ((Foot,Hour),val_*.3600.) else if from_unit = (Meter,Second) then ((Foot,Hour),snd(convert_dist (Meter,val_) Foot)*.3600.) else if from_unit = (Meter,Hour) then ((Foot,Hour),snd( convert_dist (Meter,val_) Foot)) else if from_unit = (Mile,Second) then ((Foot,Hour),snd(convert_dist (Mile,val_) Foot)*.3600.) else if from_unit = (Mile, Hour) then ((Foot,Hour),snd(convert_dist (Mile,val_) Foot)) else ((Foot,Hour),val_) |(Meter,Second)-> if from_unit = (Foot,Second) then ((Meter,Second),snd(convert_dist (Foot,val_) Meter)) else if from_unit = (Foot, Hour) then ((Meter,Second),snd(convert_dist (Foot,val_) Meter)/.3600.) else if from_unit = (Meter,Hour) then ((Meter,Second),val_/.3600.) else if from_unit = (Mile,Second) then ((Meter,Second),snd(convert_dist (Mile,val_) Meter)) else if from_unit = (Mile,Hour) then ((Meter,Second),snd(convert_dist (Mile,val_) Meter)/.3600.) else ((Meter,Second),val_) |(Meter,Hour)-> if from_unit = (Foot,Second) then ((Meter,Hour), snd(convert_dist (Foot,val_) Meter)*.3600.) else if from_unit = (Foot,Hour) then ((Meter,Hour),snd(convert_dist (Foot,val_) Meter)) else if from_unit = (Meter,Second) then ((Meter,Hour),val_*.3600.) else if from_unit = (Mile,Second) then ((Meter,Hour),snd(convert_dist (Mile,val_) Meter)*.3600.) else if from_unit = (Mile,Hour) then ((Meter,Hour),snd( convert_dist (Mile,val_) Meter)) else ((Meter,Hour),val_ ) |(Mile,Second)-> if from_unit = (Foot,Second) then ((Mile,Second),snd(convert_dist (Foot,val_) Mile)) else if from_unit = (Foot,Hour) then ((Mile,Second),snd(convert_dist (Foot,val_) Mile)/.3600.) else if from_unit = (Meter,Second) then ((Mile,Second),snd(convert_dist (Meter,val_) Mile)) else if from_unit = (Meter,Hour) then ((Mile,Second),snd(convert_dist (Meter,val_) Mile)/.3600.) else if from_unit = (Mile, Hour) then ((Mile,Second),val_/.3600.) else ((Mile,Second),val_) |(Mile,Hour)-> if from_unit = (Foot,Second) then ((Mile,Hour),snd(convert_dist (Foot,val_) Mile)*.3600.) else if from_unit = (Foot,Hour) then ((Mile,Hour),snd(convert_dist (Foot,val_) Mile)) else if from_unit = (Meter,Second) then ((Mile,Hour),snd(convert_dist (Meter,val_) Mile)*.3600.) else if from_unit = (Meter,Hour) then((Mile,Hour), snd(convert_dist (Meter,val_) Mile)) else if from_unit = (Mile,Second) then ((Mile,Hour),val_*.3600.) else ((Mile,Hour),val_) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let new_speed1 = convert_speed a b_unit in let result_speed = snd(new_speed1) +. b_val in (b_unit,result_speed) ;;
let passes_da_vinci t = let rec sum_ l acc= match l with |[]-> acc |Leaf::tl-> sum_ tl (acc+.0.) |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 width*.width >= (sum_ subtree 0.) then check subtree else false 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 | [] -> if cur_num > max_num then cur_el else max_el | x :: xs -> if cur_el = x then aux xs (cur_el, 1 + cur_num) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1) (cur_el, cur_num) else aux xs (x, 1) (max_el, max_num) in match (List.sort compare l) with | [] -> failwith "empty list" | x::xs -> aux (xs) (x, 1) (x, 1) ;; let build_list l = let rec helper l b_l = match l with | [] -> failwith "emptylist" | [x] -> b_l | x::xs -> helper xs (List.append b_l [(x, List.hd xs)]) in helper l [] ;;
let pair_mode (l: 'a list) : 'a * 'a = let b_l = build_list l in mode b_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 -> (Second, val_)) | 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 -> (Mile, (val_ /.0.3048) /. 5280.)) | Mile->(match to_unit with | Foot -> (Foot, val_ *. 5280.) | Meter -> (Meter, (val_ *. 5280.) *. 0.3048) | Mile -> (Mile, val_)) ;; let first_element pair = let (first, _) = pair in first ;; let second_element pair = let (_, second) = pair in second ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (_, val_1) = convert_time ((second_element from_unit), 1.) (second_element to_unit) in let (_, val_2) = convert_dist ((first_element from_unit), val_) (first_element to_unit) in to_unit, val_2 /. val_1 ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (_, val_1) = convert_speed a b_unit in (b_unit, val_1 +. 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 list = match list with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if sum_ subtree 0. > width ** 2. then false else 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 | [] -> if cur_num > max_num then cur_el else max_el | hd :: xs -> if cur_el = hd then aux xs (cur_el, cur_num+1) (max_el,max_num) else if cur_num > max_num then aux xs (hd, 1) (cur_el,cur_num) else aux xs (hd, 1) (max_el,max_num) in match (List.sort compare l) with | [] -> failwith "empty list" | hd :: ls -> aux ls (hd ,1) (hd , 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = let l1 = l in let l2= l in let (_ :: l1_c ) = l in let (_ :: l2_t ) = List.rev l in let l2_c = List.rev l2_t in let l_combined = List.combine l2_c l1_c in mode l_combined ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) with | (Second,_) -> if to_unit = Second then (Second, val_) else (Hour, val_ /. 3600.) | (Hour,_ ) -> if to_unit = Hour then (Hour, val_) else (Second, val_ *. 3600.) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, val_) with | (Foot,_) -> if to_unit = Foot then (Foot, val_) else if to_unit = Meter then (Meter, val_ *. 0.3048 ) else (Mile, val_ /. 5280.) | (Meter,_ ) -> if to_unit = Meter then (Meter, val_) else if to_unit = Foot then (Foot, val_ /. 0.3048 ) else (Mile, val_ /. 0.3048 /. 5280.) | (Mile,_ ) -> if to_unit = Mile then (Mile, val_) else if to_unit = Foot then (Foot, val_ *. 5280. ) else ( Meter, val_ *. 5280. *. 0.3048) ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_ = snd (convert_dist (fst from_unit, val_) (fst to_unit)) in let inv_ = snd (convert_time (snd from_unit, 1.) (snd to_unit)) in (to_unit, dist_ /. inv_) ;;
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_square l sum= match l with | [] -> sum | x ::xs -> ( match x with | Leaf -> sum_square xs sum | Branch (y,_)-> sum_square xs sum +. y *. y ) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not (check subtree && width *. width >= sum_square subtree 0.) then false else 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) = notimplemented () in match List.sort compare l with | [] -> failwith "Error: empty list" | [x] -> x | x::xs -> x ;;
let pair_mode (l: 'a list) : 'a * 'a = notimplemented () ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Second -> (Second, val_) | Second, Hour -> (Hour, val_ /. 3600.0) | Hour, Second -> (Second, val_ *. 3600.0) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Meter, Foot -> (Foot, val_ /. 0.3048); | Meter, Mile -> (Mile, val_ /. 1609.344); | Foot, Meter -> (Meter, val_ *. 0.3048); | Foot, Mile -> (Mile, val_ /. 5280.0); | Mile, Foot -> (Foot, val_ *. 5280.0); | Mile, Meter -> (Meter, val_ *. 1609.344); | Meter, Meter -> (Meter, val_); | Mile, Mile -> (Mile, val_); | Foot, Foot -> (Foot, val_); ;;
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let old_time_unit : time_unit = snd(from_unit) in let new_time_unit : time_unit = snd(to_unit) in let old_dist_unit : dist_unit = fst(from_unit) in let new_dist_unit : dist_unit = fst(to_unit) in let new_time : float = snd(convert_time (old_time_unit, 1.0) new_time_unit) in let new_dist : float = snd(convert_dist (old_dist_unit, val_) new_dist_unit) in (to_unit, new_dist /. new_time) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let speed_a_converted = convert_speed (a) b_unit in let new_speed_a_val : float = snd(speed_a_converted) in (b_unit, new_speed_a_val +. b_val) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> acc | Branch (width, subtree) :: tl -> sum_ subtree (width*.width +. acc) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not ((check subtree) && ((sum_ subtree 0.) <= (width*.width))) then false else 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 | [] -> max_el | hd :: tl -> if hd = cur_el && cur_num + 1 <= max_num then aux tl (cur_el, cur_num+1) (max_el, max_num) else if hd = cur_el && cur_num + 1 > max_num then aux tl (cur_el, cur_num+1) (cur_el, cur_num+1) else aux tl (hd, 1) (max_el, max_num) in match (List.sort compare(l)) with | [] -> failwith "It doesn't work" | hd :: tl -> aux (List.sort compare(tl)) (hd, 1) (hd, 1) ;;
let pair_mode (l: 'a list) : 'a * 'a = let rec copy_l (l1: 'a list) (l2: ('a * 'a) list) : ('a * 'a) list = match l1 with | [] -> failwith "It doesn't work" | h::t -> if (List.length l1)> 1 then copy_l t (List.append [(h,(List.hd t))] l2) else l2 in if (List.length l >= 2) then mode (copy_l l []) else failwith "It doesn't work" ;;