text
stringlengths
0
601k
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if (to_unit = from_unit) then (from_unit,val_) else if to_unit = Hour then (Hour, val_ /. 3600.) else (Second, val_ *. 3600.) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if (to_unit = from_unit) then (from_unit,val_) else match to_unit with | Mile -> if from_unit = Foot then (Mile, val_ /. 5280.) else (Mile, (val_ /. 0.3048) /. 5280.) | Foot -> if from_unit = Meter then (Foot,(val_ /. 0.3048)) else (Foot...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let t1 = get_time from_unit in let d1 = get_dist from_unit in let t2 = get_time to_unit in let d2 = get_dist to_unit in (to_unit,(get_val(convert_dist (d1,val_) d2)) /.(get_val(convert_time (t1,1.) t2)));;
let dist_traveled (time : time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let tim = get_time speed_unit in let dis = get_dist speed_unit in (dis, get_val(convert_time time tim) *.speed_val) let rec passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ 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 | h::t -> if h = cur_el then aux t (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux t (h, 1) (cur_el, cur_num) else aux t ...
let pair_mode (l: 'a list) : 'a * 'a = match (l, List.rev l) with | ([], _) | (_, []) -> failwith "Undefined input." | (h::[], _) -> failwith "Undefined input." | (h1::t1, h2::t2) -> mode (List.combine (List.rev t2) t1) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Second) | (Hour, Hour) -> (to_unit, val_) | (Second, Hour) -> (to_unit, val_ /. 3600.) | (Hour, Second) -> (to_unit, val_ *. 3600.) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Foot) | (Meter, Meter) | (Mile, Mile) -> (to_unit, val_) | (Foot, Meter) -> (to_unit, val_ *. 0.3048) | (Foot, Mile) -> (to_unit, val_ /. 5280.) | (Meter, Foot) -> (to_unit, val_ /. 0.3048) | (Met...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match (snd from_unit, snd to_unit) with | (Second, Second) | (Hour, Hour) -> (to_unit, snd (convert_dist (fst from_unit, val_) (fst to_unit))) | (Second, Hour) -> (to_unit, snd (convert_dist (fst from_unit, val_) (fst to_unit)) *. 360...
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 summation l acc = match l with | [] -> acc | Leaf :: tl -> summation tl acc | Branch (width, subtree) :: tl -> summation tl acc +. (width**2.) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && (summation subt...
let mode (l: 'a list) : 'a = if l = [] then failwith "input is invalid, cannot be empty list"; let y = List.sort compare (l) in let x = List.hd (l) in 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 max_el else cur_el | ob_el :: l -> if cur_e...
let pair_mode (l: 'a list) : 'a * 'a = if ( List.length(l) < 2 ) then failwith "input is invalid (list length is less than 2)"; let l1 = List.tl (l) in let l2 = List.rev(List.tl (List.rev(l))) in let y = List.combine (l2) (l1) in mode(y) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> ( if to_unit = Second then (Second , (val_) ) else (Hour , (val_ /. 3600.) )) | Hour -> ( if to_unit = Hour then (Hour , (val_) ) else (Second , (3600. *. val_) )) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit 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 = Mile the...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let time = snd(from_unit) in let dist = fst(from_unit) in let new_time = snd(to_unit) in let new_dist = fst(to_unit) in let converted_time = convert_time (time, 1.) new_time in let converted_dist = convert_dist (dist, 1.) new_dist in ...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed_time = snd(speed_unit) in let speed_dist = fst(speed_unit) in let new_time = convert_time time speed_time in let new_time_value = snd(new_time) in let calculated_dist = (speed_dist, new_time_value *. speed_val) in calculat...
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 -> (match x with | z when z = max_el -> aux xs (z, max_num+1) (z, max_num+1) | y when y = cur_el -> (if cur_num+1 > max_num then aux xs (...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "List must have at least two elements" else 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.) | _, _ -> (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 -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, (val_ /. 0.3048) /. 5280.) | Mile, Foot -> (Foot, val_ *. 5280.)...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit, to_unit with | (x, Second), (y, Second) -> ((y, Second), snd(convert_dist (x, val_) y)) | (x, Hour), (y, Hour) -> ((y, Hour), snd(convert_dist (x, val_) y)) | (x, Hour), (y, Second) -> ((y, Second), snd(convert_dist (...
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 passes_da_vinci_list (l : tree list) = match l with | [] -> true | Leaf :: tl -> passes_da_vinci_list tl | Branch (width, subtree) :: tl -> (if not ((width *. width >= square_of_st subtree) && (passes_da_vinci_list subtree)) then false else passes_da_vinci_list tl) in passes_da_vinci_lis...
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 -> (match x with | z when z = max_el -> aux xs (z, max_num+1) (z, max_num+1) | y when y = cur_el -> (if cur_num+1 > max_num then aux xs (...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "List must have at least two elements" else 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.) | _, _ -> (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 -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, (val_ /. 0.3048) /. 5280.) | Mile, Foot -> (Foot, val_ *. 5280.)...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit, to_unit with | (x, Second), (y, Second) -> ((y, Second), snd(convert_dist (x, val_) y)) | (x, Hour), (y, Hour) -> ((y, Hour), snd(convert_dist (x, val_) y)) | (x, Hour), (y, Second) -> ((y, Second), snd(convert_dist (...
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 passes_da_vinci_list (l : tree list) = match l with | [] -> true | Leaf :: tl -> passes_da_vinci_list tl | Branch (width, subtree) :: tl -> (if not ((width *. width >= square_of_st subtree) && (passes_da_vinci_list subtree)) then false else passes_da_vinci_list tl) in passes_da_vinci_lis...
let num el l = List.length (List.filter (fun x -> (x == List.nth l el)) 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 max_el else cur_el | hd :: tl when (hd = cur_el) -> aux (tl) (hd, (cur_num + 1)) (max_el, max_num) | hd :: tl -> (if cur_num <= max_num then (aux (tl) (hd, 1) (max...
let pair_mode (l: 'a list) : 'a * 'a = let rec tuples l new_l = if (List.length l < 2) then (new_l) else (tuples (List.tl l) (List.append new_l [(List.hd l, List.hd (List.tl l))])) in if (List.length l < 2) then failwith "Invalid input" else mode (tuples l []) ;;
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.) | (_, _) -> (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) -> (Meter, val_ *. 0.3048) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Meter, Mile) -> (Mile, (val_ /. 0.304...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (a, b) = from_unit in let (c, d) = to_unit in let (dist_u, dist_val) = convert_dist (a, val_) c in let (time_u, time_val) = convert_time (d, dist_val) b in ((dist_u, time_u), time_val) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let ((_, _), value) = convert_speed a b_unit in ((b_unit), b_val +. value) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch (width, _) :: 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.))...
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 xs (x...
let pair_mode (l: 'a list) : 'a * 'a = let rec func l = match l with | [] -> [] | x::[] -> [] | x::xs -> (x, List.hd xs)::func xs in match l with | [] -> failwith "Invalid bigram list" | x::[] -> failwith "Invalid bigram list" | _ -> let a = func l in mode a ;;
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_) | _ -> failwith "Invalid unit conversion") | Hour -> (match to_unit with | Second -> (Second, val_ *. 3600.) | Hour -> (Hour,...
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.) | _ -> failwith "Invalid unit conversion") | Meter -> (match to_unit with | Meter -> (Meter, val...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let d_from_unit = fst from_unit in let t_from_unit = snd from_unit in let d_to_unit = fst to_unit in let t_to_unit = snd to_unit in let dist = convert_dist (d_from_unit, val_) d_to_unit in let time = convert_time (t_from_unit, 1.) t_t...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let converted_time = convert_time time (snd speed_unit) in let result = speed_val *. (snd converted_time) in (fst speed_unit, result) ;; let get_direct_children (tr: tree) : tree list = match tr with | Leaf -> [] | Branch(x,y) -> y ...
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 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 xs ...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Invalid input" else 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, val_), to_unit) with | ((Second, val_), Second) -> (Second, val_) | ((Second, val_), Hour) -> (Hour, (val_/.3600.0)) | ((Hour, val_), Hour) -> (Hour, val_) | ((Hour, val_), Second) -> (Second, (val_*.3600.0)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match ((from_unit, val_), to_unit) with | ((Foot, val_), Foot) -> (Foot, val_) | ((Foot, val_), Meter) -> (Meter, (val_*.0.3048)) | ((Foot, val_),Mile) -> (Mile, (val_/.5280.0)) | ((Meter, val_), Meter) -> (Meter, val_) | ((Meter, val_),...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist0 = fst from_unit in let time0 = snd from_unit in let dist = fst to_unit in let time = snd to_unit in let d = snd (convert_dist (dist0, val_) dist) in let t = snd (convert_time(time0, 1.0) time) in (to_unit, d /. t) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_speed = snd (convert_speed (fst a, snd a) b_unit) in (b_unit, b_val +. a_speed) ;;
let passes_da_vinci t = let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (w,s) :: tl -> if (check s && sum_ (Branch (w,s)) <= w*.w) 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) = function | [] -> if cur_num > max_num then cur_el else max_el | hd :: tl -> if hd = cur_el then aux l (cur_el, cur_num + 1) (max_el,max_num) tl else if cur_num > max_num then aux l (hd,1) (cur_el, cur_num) tl else...
let pair_mode (l: 'a list) : 'a * 'a = let list1 = List.tl l in let list2 = List.rev (List.tl (List.rev l )) in let combine = List.combine list2 list1 in mode combine ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) with | (Second , _ ) -> if to_unit = Hour then ( Hour, val_ /. 3600.) else (from_unit, val_) | (Hour, _ ) -> if to_unit = Second then ( Second, val_ *. 3600.) else (from_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if to_unit = Foot then match (from_unit, val_) with | ( Mile, _ ) -> ( Foot, val_ *. 5280.) | ( Meter, _ ) -> ( Foot, val_ /. 0.3048) | ( Foot, _) -> ( Foot, val_) else if to_unit = Meter then match (from_unit, val_) with | ( Foot, _ ) -...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist,time) = from_unit in let (to_dist, to_time) = to_unit in let ( _ , dist_value) = convert_dist (dist, val_) to_dist in match time with | Second -> if to_time = Hour then (to_unit, dist_value *. 3600.) else (to_unit, dist_valu...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (a_unit,a_val) = a in let ( _ , a_in_b_value) = convert_speed (a_unit, a_val) b_unit in ( b_unit, a_in_b_value +. 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 -> match check subtree with | false -> false | true -> ...
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 && cur_num+1 > max_num then aux t (cur_el, cur_num+1) (cur_el, cur_num+1) else if h = cur_el && cur_num+1 <= max_num then aux t (cur_el, cur_num+1) (max_el, max_...
let pair_mode (l: 'a list) : 'a * 'a = let rec make_l (l1: 'a list) (l2: ('a * 'a) list) : ('a * 'a) list = match l1 with | [] -> failwith "This not works." | h::t -> if (List.length l1)> 1 then make_l t (List.append [(h,(List.hd t))] l2) else l2 in if (List.length l < 2) then failwith "This not works. " else mode (mak...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if (to_unit = from_unit) then (from_unit,val_) else match to_unit with | Hour -> (Hour,(val_ /. 3600.)) | Second -> (Second,(val_ *. 3600.)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if (to_unit = from_unit) then (from_unit,val_) else match to_unit with | Foot -> if (from_unit = Meter)then (Foot,(val_ /. 0.3048)) else (Foot,(val_*.5280.)) | Meter -> if (from_unit = Foot)then (Meter,(val_ *. 0.3048)) else (Meter,((val...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let t1=get_time from_unit in let d1=get_dist from_unit in let t2=get_time to_unit in let d2=get_dist to_unit in (to_unit,(get_val(convert_dist (d1,val_) d2))/.(get_val(convert_time (t1,1.) t2))) ;;
let dist_traveled (time : time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let t=get_time speed_unit in let d=get_dist speed_unit in (d,get_val(convert_time time t)*.speed_val) ;; let get_square (t: tree) : float = match t with | Leaf -> 0. | Branch (f, _) -> f*.f ;; let rec get_list_sq...
let mode (l: 'a list) : 'a = match l with | [] -> failwith "Undefined input." | _ -> let rec aux (l : 'a list) ((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 x = max_el then aux xs (cur_el, 1 + cur_num) (cur_el, 1 + cur_num) else if cur_num...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Undefined input." else mode (create_list_of_tuples l) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit = Hour then (Hour, val_ /. 3600.0) else (from_unit, val_) | Hour -> if to_unit = Second then (Second, val_ *. 3600.0) else (from_unit, 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.0) | Foot -> (from_unit, val_)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Mile -> (Mile, val_ /. ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (input_dist,input_time) = from_unit in let (output_dist,output_time) = to_unit in (output_dist, output_time),(snd(convert_dist (input_dist, val_) output_dist) /. snd(convert_time (input_time, 1.0) output_time)) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = fst(speed_unit), (snd((convert_time time (snd(speed_unit)))) *. speed_val) ;; let square_count (tr) : float = let rec count_helper (tre) (result : float) : float = match tre with | [] -> result | Leaf :: rest -> count_helper rest re...
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 if cur_num > max_num || (cur_num == max_num && cur_el < max_el...
let pair_mode (l: 'a list) : 'a * 'a = if l == [] then failwith "Empty list" else let l1 = List.tl l and l2 = List.rev (List.tl (List.rev l)) in let superList = List.combine l2 l1 in mode superList ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit == Second then (to_unit, val_) else if to_unit == Hour then (to_unit, val_ /. 3600.) else failwith "Wrong data type to convert to" | Hour -> if to_unit == Second then (to_unit, val_ *. 3600.) e...
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> if to_unit == Meter then (to_unit, val_ *. 0.3048) else if to_unit == Mile then (to_unit, val_ /. 5280.) else if to_unit == Foot then (to_unit, val_) else failwith "Wrong data type to convert to" | Mile -> ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let time = convert_time (snd(from_unit), 1.) (snd(to_unit)) and distance = convert_dist (fst(from_unit), val_) (fst(to_unit)) in (((fst(distance),(fst(time)))), (snd(distance)) /. (snd(time))) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let timmar = convert_time time (snd(speed_unit)) in (fst(speed_unit), snd(timmar) *. speed_val ) ;; let rec passes_da_vinci t = notimplemented () ;;
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 | [] -> notimplemented() | x :: xs -> aux l (x,0) (x,0) ;;
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, val_) with | (Hour, _) -> (match to_unit with | Hour -> (to_unit, snd(from_unit, val_)) | Second -> (to_unit, snd(from_unit, val_) *. 3600.)) | (Second, _) -> (match to_unit with | Second -> (to_unit, snd(from_unit, val...
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (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.)) | (Meter, _) -> (match to_...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_unit = fst(to_unit) and time_unit = snd(to_unit) and value = snd(from_unit, val_) in let dist_value = snd(convert_dist (fst from_unit, val_) dist_unit) and time_value = snd(convert_time (snd from_unit, 1.) time_unit) in match...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = notimplemented () ;; let rec passes_da_vinci t = notimplemented () ;;
let domainError () = failwith "Domain is not correct" let compare (a: ('a * int)) (b: ('a * int)): int = let count_a = snd a in let count_b = snd b in if (count_a - count_b) = 0 then (if (fst a) > (fst b) then 1 else -1) else count_b - count_a ; ;; let rec find_add (el:'a) (counts: ('a * int) list): ('a * int) list = m...
let mode (l: 'a list) : 'a = if List.length l < 1 then domainError () else count l |> List.sort compare |> List.hd |> fst;; let rec make_bi_pairs (l: 'a list) : ('a * 'a) list = match l with | [] -> [] | [_] -> [] | x1 :: x2 :: xs -> (x1, x2) :: make_bi_pairs (x2::xs) ;;
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then domainError () else mode (make_bi_pairs l) ;;
let convert_time ((from_unit, val_) : time_unit value) (to_unit : time_unit): time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (Hour, val_ /. 3600.) | (Hour, Second) -> (Second, val_ *. 3600.) | _ -> (to_unit, val_) ;; let rec convert_dist ((from_unit, val_) : dist_unit value) (to_unit: dist_unit) ...
let dist_traveled (time : time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (fst speed_unit, speed_val *. (snd (convert_time time (snd speed_unit)))) ;; let get_thkns (tr : tree) : float = match tr with | Leaf -> 0. | Branch (w, _) -> w let check_valid (w: float) (sub: tree list): bool =...
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 (xs != [] && x = List.hd(xs)) then aux xs (x, cur_num + 1) (max_el, max_num) else if xs != [] then if (max_num < cur_num) then aux xs (List.hd(xs), 1) (cur_el, cur_num) ...
let pair_mode (l: 'a list) : 'a * 'a = let rec make_pairs b pairs = if List.length b < 2 then pairs else let tupl = (List.nth b 0, List.nth b 1) in make_pairs (List.tl b) (tupl::pairs) in if List.length l < 2 then failwith "The input list should have length at least 2" else mode (make_pairs l []) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> if from_unit = to_unit then (to_unit, val_) else to_unit, (val_ *. 3600.) | Hour -> if from_unit = to_unit then (to_unit, val_) else to_unit, val_ *. (1. /. 3600.) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> if from_unit = to_unit then (to_unit, val_) else if from_unit = Meter then to_unit, val_ *. (1. /. 0.3048) else to_unit, val_ *. 5280. | Meter -> if from_unit = to_unit then (to_unit, val_) else if from_unit ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let from_time = snd from_unit in let to_time = snd to_unit in let (a,x) = convert_time (from_time, 1.) to_time in let from_dist = fst from_unit in let to_dist = fst to_unit in let (b,y) = convert_dist (from_dist, 1.) to_dist in to_uni...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let time_unit, time_val = time in let to_time_unit = snd speed_unit in let a, time_taken = convert_time (time_unit, time_val) to_time_unit in fst speed_unit, speed_val *. time_taken ;; let rec passes_da_vinci t = let rec sum_ l acc ...
let invalid () = failwith "Invalid input";;
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 (hd, cur_num+1) (max_el, max_num) else (if cur_num > max_num then aux tl (hd , 1) (cur_el, cur_num) else a...
let pair_mode (l: 'a list) : 'a * 'a = if List.length (l) < 2 then invalid() else (let l1 = List.tl (l) in let l2 = List.rev(l) in let l2 = List.tl (l2) in let l2 = List.rev(l2) in let l3 = List.combine(l2)(l1) in mode (l3) ) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let temp = (from_unit, val_) in if fst(temp) = to_unit then temp else if fst(temp) = Second then (to_unit,snd(temp) /. 3600.) else (to_unit,snd(temp) *. 3600.) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let temp = (from_unit, val_) in if fst(temp) = to_unit then temp else match fst(temp) with | Foot -> (if to_unit = Meter then (to_unit,snd(temp) *. 0.3048) else (to_unit, snd(temp) /. 5280.)) | Meter -> (if to_unit = Foot then (to_unit, ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let temp = (from_unit, val_) in let initialdist = fst(fst(temp)) in let initialtime = snd(fst(temp)) in let wanteddist = fst(to_unit) in let wantedtime = snd(to_unit) in if initialdist = wanteddist && initialtime = wantedtime then tem...