text
stringlengths 0
601k
|
---|
let passes_da_vinci t = let rec sum_ l acc = match l with | Branch (width, subtree) :: tl -> sum_ tl (acc +. width**2.) | Leaf :: tl -> sum_ tl acc | [] -> 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**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 ) | x :: xs -> ( if x = cur_el then ( if cur_num > 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_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 let l1 = List.sort compare l in match l1 with | [] -> failwith "List must have a minimum size of 1" | x :: xs -> aux xs (x, 1) (x, 1) ;; let rec make_tuples l1 : ('a * 'a) list = match l1 with | x1 :: x2 :: xs -> List.append [(x1,x2)] (make_tuples (x2 :: xs)) | _ -> [] ;; |
let pair_mode (l: 'a list) : 'a * 'a = match l with | _ :: _ :: _ -> mode (make_tuples l) | _ -> failwith "List must have a minimum size of 2" ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit = to_unit then (to_unit,val_) else ( match to_unit with | Second -> (Hour,val_*.3600.) | Hour -> (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 | Meter -> (Meter, val_*.0.3048) | Mile -> (Mile, val_/.5280.) | Foot -> (to_unit, val_) ) | Meter -> ( match to_unit with | Foot -> (Foot, val_/.0.3048) | Mile -> (Mile, val_/.(5280.*.0.3048)) | Meter -> (to_unit, val_) ) | Mile -> ( match to_unit with | Foot -> (Foot, val_*.5280.) | Meter -> (Meter, val_*.(5280.*.0.3048)) | Mile -> (to_unit, val_) ) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (f_dist, f_time) = from_unit in let (t_dist, t_time) = to_unit in let ans_val1 = snd (convert_dist (f_dist, val_) t_dist) in let ans_val2 = snd (convert_time (f_time, 1.) t_time) in to_unit, ans_val1/.ans_val2 ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (d_unit, t_unit) = speed_unit in let t_val1 = snd (convert_time time t_unit) in d_unit, speed_val*.t_val1 ;; let rec sum_of_squares l : float = match l with | [] -> 0. | x :: xs -> match x with | Leaf -> 0. +. sum_of_squares xs | Branch (x_val, _) -> x_val**2. +. sum_of_squares xs ;; let rec passes_da_vinci t = match t with | Leaf -> true | Branch (t_val, t_list) -> ( if (t_val**2. < sum_of_squares t_list) then false else let rec traverse_list l = match l with | [] -> true | x :: xs -> match x with | Leaf -> true && traverse_list xs | _ -> passes_da_vinci x && traverse_list xs in traverse_list t_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 |[] -> if cur_num > max_num then cur_el else max_el |hd :: tl -> let cur_num = if hd = cur_el then cur_num+1 else 1 in let cur_el = if hd = cur_el then cur_el else hd in let max_el = if cur_num > max_num then cur_el else max_el in let max_num = if cur_num > max_num then cur_num else max_num in aux tl (cur_el, cur_num) (max_el, max_num) in match l with |[] -> failwith "invalid input" |_ -> let l = List.sort compare l in let i = List.hd l in aux l (i, 0) (i, 1) ;; |
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 lc = List.combine l2 l1 in mode lc ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match fst(from_unit, val_), to_unit with | Second, Hour -> (Hour, val_ /. 3600.) |Hour, Second -> (Second, val_ *. 3600.) |from_unit, to_unit -> (to_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match fst(from_unit, val_), 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_ /. 1609.344) |Mile, Meter -> (Meter, val_ *. 1609.344) |Mile, Mile -> (Mile, val_ ) |Meter, Meter -> (Meter, val_) |Foot, Foot -> (Foot, val_ ) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match fst(from_unit, val_), to_unit with |_ -> ( ( fst(convert_dist (fst(from_unit), val_) (fst(to_unit))), fst(convert_time (snd(from_unit), val_) (snd(to_unit))) ), (val_ *. ( snd(convert_dist (fst(from_unit), val_) (fst(to_unit))) /. snd(convert_time (snd(from_unit), val_) (snd(to_unit))) )) ) ;; |
let dist_traveled ((t_unit, t_val) : time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let t = convert_time (t_unit, t_val) (snd(speed_unit)) in let d = snd(t) *. speed_val in (fst(speed_unit), d) ;; 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) = match l with |[] -> if cur_num > max_num then cur_el else max_el |_ -> let hd = List.hd l in if hd = cur_el then aux (List.tl l) (hd, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux (List.tl l) (hd, 1) (cur_el, cur_num) else aux (List.tl l) (hd, 1) (max_el, max_num) in if l = [] then failwith "List can't be empty" else let l = List.sort compare l in let hd_el = List.hd l in aux (List.tl l) (hd_el, 1) (hd_el, 1) ;; |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Invalid input! List must be of length greater or equal to 2" else let l1 = List.rev (List.tl (List.rev l)) and l2 = List.tl l in let tuple_ls = List.combine l1 l2 in mode tuple_ls ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit = to_unit then (from_unit, val_) else match to_unit with |Second -> (to_unit, val_ *. 3600.) |_ -> (to_unit, val_ /. 3600. ) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit = to_unit then (from_unit, val_) else if from_unit = Foot then match to_unit with |Mile -> (to_unit, val_ /. 5280.) |_ -> (to_unit, val_ *. 0.3048) else if from_unit = Meter then match to_unit with |Foot -> (to_unit, val_ /. 0.3048) |_ -> (to_unit, val_ /. 0.3048 /. 5280.) else match to_unit with |Foot -> (to_unit, val_ *. 5280.) |_ -> (to_unit, val_ *. 0.3048 *. 5280.) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (from_unit, val_) else if snd(from_unit) = snd(to_unit) then let from_dist_unit = fst(from_unit) and to_dist_unit = fst(to_unit) in (to_unit, (snd(convert_dist (from_dist_unit, val_) to_dist_unit) )) else if fst(from_unit) = fst(to_unit) then let from_time_unit = snd(from_unit) and to_time_unit = snd(to_unit) in (to_unit, (snd(convert_time (to_time_unit, val_) from_time_unit) )) else let from_dist_unit = fst(from_unit) and to_dist_unit = fst(to_unit) in let val_ = snd(convert_dist (from_dist_unit, val_) to_dist_unit) in let from_time_unit = snd(from_unit) and to_time_unit = snd(to_unit) in (to_unit, (snd(convert_time (to_time_unit, val_) from_time_unit) )) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if fst(a) = b_unit then (b_unit, snd(a) +. b_val) else let new_a = convert_speed a b_unit in (b_unit, snd(new_a) +. b_val ) ;; |
let passes_da_vinci t = true in let rec check l = match l with | [] -> | Leaf :: tl -> | Branch (width, subtree) :: 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 |_ -> let hd = List.hd l in if hd = cur_el then aux (List.tl l) (hd, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux (List.tl l) (hd, 1) (cur_el, cur_num) else aux (List.tl l) (hd, 1) (max_el, max_num) in if l = [] then failwith "List can't be empty" else let l = List.sort compare l in let hd_el = List.hd l in aux (List.tl l) (hd_el, 1) (hd_el, 1) ;; |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Invalid input! List must be of length greater or equal to 2" else let l1 = List.rev (List.tl (List.rev l)) and l2 = List.tl l in let tuple_ls = List.combine l1 l2 in mode tuple_ls ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit = to_unit then (from_unit, val_) else match to_unit with |Second -> (to_unit, val_ *. 3600.) |_ -> (to_unit, val_ /. 3600. ) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit = to_unit then (from_unit, val_) else if from_unit = Foot then match to_unit with |Mile -> (to_unit, val_ /. 5280.) |_ -> (to_unit, val_ *. 0.3048) else if from_unit = Meter then match to_unit with |Foot -> (to_unit, val_ /. 0.3048) |_ -> (to_unit, val_ /. 0.3048 /. 5280.) else match to_unit with |Foot -> (to_unit, val_ *. 5280.) |_ -> (to_unit, val_ *. 0.3048 *. 5280.) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (from_unit, val_) else if snd(from_unit) = snd(to_unit) then let from_dist_unit = fst(from_unit) and to_dist_unit = fst(to_unit) in (to_unit, (snd(convert_dist (from_dist_unit, val_) to_dist_unit) )) else if fst(from_unit) = fst(to_unit) then let from_time_unit = snd(from_unit) and to_time_unit = snd(to_unit) in (to_unit, (snd(convert_time (to_time_unit, val_) from_time_unit) )) else let from_dist_unit = fst(from_unit) and to_dist_unit = fst(to_unit) in let val_ = snd(convert_dist (from_dist_unit, val_) to_dist_unit) in let from_time_unit = snd(from_unit) and to_time_unit = snd(to_unit) in (to_unit, (snd(convert_time (to_time_unit, val_) from_time_unit) )) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if fst(a) = b_unit then (b_unit, snd(a) +. b_val) else let new_a = convert_speed a b_unit in (b_unit, snd(new_a) +. 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 |[] -> if cur_num > max_num then cur_el else max_el |hd::subl -> if hd = cur_el then aux subl (hd, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux subl (hd, 1) (cur_el, cur_num) else aux subl (hd, 1) (max_el, max_num) in if l = [] then failwith "List can't be empty" else let l = List.sort compare l in let hd_el = List.hd l in aux (List.tl l) (hd_el, 1) (hd_el, 1) ;; |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Invalid input! List must be of length greater or equal to 2" else let l1 = List.rev (List.tl (List.rev l)) and l2 = List.tl l in let tuple_ls = List.combine l1 l2 in mode tuple_ls ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit = to_unit then (from_unit, val_) else match to_unit with |Second -> (to_unit, val_ *. 3600.) |_ -> (to_unit, val_ /. 3600. ) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit = to_unit then (from_unit, val_) else if from_unit = Foot then match to_unit with |Mile -> (to_unit, val_ /. 5280.) |_ -> (to_unit, val_ *. 0.3048) else if from_unit = Meter then match to_unit with |Foot -> (to_unit, val_ /. 0.3048) |_ -> (to_unit, val_ /. 0.3048 /. 5280.) else match to_unit with |Foot -> (to_unit, val_ *. 5280.) |_ -> (to_unit, val_ *. 0.3048 *. 5280.) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (from_unit, val_) else let from_dist_unit = fst(from_unit) and to_dist_unit = fst(to_unit) in let val_ = snd(convert_dist (from_dist_unit, val_) to_dist_unit) in let from_time_unit = snd(from_unit) and to_time_unit = snd(to_unit) in (to_unit, snd(convert_time (to_time_unit, val_) from_time_unit)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if fst(a) = b_unit then (b_unit, snd(a) +. b_val) else let new_a = convert_speed a b_unit in (b_unit, snd(new_a) +. 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 | [] -> if cur_num > max_num then cur_el else max_el | hd :: td -> if hd = cur_el then aux td (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num && cur_el <= max_el then aux td (hd,1) (cur_el,cur_num) else aux td (hd, 1) (max_el, max_num) in match List.sort compare l with | [] -> failwith "list cannot be empty" | hd :: td -> (aux l (hd, 0) (hd, 1)) ;; let rec remove_el index = function | [] -> [] | hd :: tl -> if index = 0 then tl else hd::remove_el (index-1) tl;; |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "list cannot be empty" | hd :: td -> let (_ :: no_head) = l in let (_:: no_head) = List.rev(List.rev(no_head)) in let l1 = no_head in let l2 = l1 in mode(List.combine l1 l2) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let unit_from = fst(from_unit,val_) in let init_val = snd(from_unit,val_) in match (unit_from,to_unit) with | (Second,Second) | (Hour,Hour) -> (to_unit, val_) | (Second, Hour) -> (to_unit, init_val /. 3600.) | (Hour,Second) -> (to_unit, init_val *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let unit_from = fst(from_unit,val_) in let init_val = snd(from_unit,val_) in match (unit_from,to_unit) with | (Foot,Foot) | (Meter, Meter) | (Mile, Mile) -> (to_unit, init_val) | (Foot, Meter) -> (to_unit, init_val *. 0.3048) | (Meter, Foot) -> (to_unit, init_val /. 0.3048) | (Foot, Mile) -> (to_unit, init_val /. 5280.) | (Mile, Foot) -> (to_unit, init_val *. 5280.) | (Meter, Mile) -> (to_unit, init_val /. 1609.344) | (Mile, Meter) -> (to_unit, init_val *. 1609.344) ;; let first_element (pair : 'a * 'b) : 'a = let (first, _) = pair in first let second_element ((a, b) : 'a * 'b) : 'b = b;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_unit = first_element(from_unit) in let time_unit = second_element(from_unit) in let to_dist = first_element(to_unit) in let to_time = second_element(to_unit) in match (dist_unit, time_unit,to_dist, to_time) with | (_, Hour, _, Second) -> let converted_time = second_element(convert_time (Second, val_) Hour) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) | (_, Second, _, Hour) -> let converted_time = second_element(convert_time (Hour, val_) Second) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) | (_, _, _, _) -> let converted_time = second_element(convert_time (time_unit, val_) to_time) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_unit = fst a in let a_val = snd a in let converted_aSpeed = convert_speed(a_unit, a_val) b_unit in ((fst b_unit, snd b_unit), b_val +. snd converted_aSpeed ) ;; |
let passes_da_vinci t = let rec summation l acc = match l with | [] -> acc | Leaf :: tl -> summation (tl) (acc) | Branch(width, subtree) :: tl -> let subtree_sum = summation (subtree) ((width ** 2.) +. acc) in summation (tl) (subtree_sum) in let rec check l = match l with | [] -> true; | Leaf :: td -> check td | Branch (width, subtree) :: tl -> let check_child = check(subtree) in if ((summation (subtree) (0.) >= width ** 2.) ) then false else if (not(check_child) && (summation (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 :: td -> if hd = cur_el then aux td (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num && cur_el < max_el then aux td (hd,1) (cur_el,cur_num) else if cur_num > max_num && cur_el >= max_el then aux td (cur_el, cur_num+1) (max_el, max_num) else aux td (hd, 1) (max_el, max_num) in match List.sort compare l with | [] -> failwith "list cannot be empty" | hd :: td -> (aux l (hd, 0) (hd, 1)) ;; let rec remove_el index = function | [] -> [] | hd :: tl -> if index = 0 then tl else hd::remove_el (index-1) tl;; |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "list cannot be empty" | hd :: td -> let (_ :: no_head) = l in let (_:: no_head) = List.rev(List.rev(no_head)) in let l1 = no_head in let l2 = l1 in mode(List.combine l1 l2) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let unit_from = fst(from_unit,val_) in let init_val = snd(from_unit,val_) in match (unit_from,to_unit) with | (Second,Second) | (Hour,Hour) -> (to_unit, val_) | (Second, Hour) -> (to_unit, init_val /. 3600.) | (Hour,Second) -> (to_unit, init_val *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let unit_from = fst(from_unit,val_) in let init_val = snd(from_unit,val_) in match (unit_from,to_unit) with | (Foot,Foot) | (Meter, Meter) | (Mile, Mile) -> (to_unit, init_val) | (Foot, Meter) -> (to_unit, init_val *. 0.3048) | (Meter, Foot) -> (to_unit, init_val /. 0.3048) | (Foot, Mile) -> (to_unit, init_val /. 5280.) | (Mile, Foot) -> (to_unit, init_val *. 5280.) | (Meter, Mile) -> (to_unit, init_val /. 1609.344) | (Mile, Meter) -> (to_unit, init_val *. 1609.344) ;; let first_element (pair : 'a * 'b) : 'a = let (first, _) = pair in first let second_element ((a, b) : 'a * 'b) : 'b = b;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_unit = first_element(from_unit) in let time_unit = second_element(from_unit) in let to_dist = first_element(to_unit) in let to_time = second_element(to_unit) in match (dist_unit, time_unit,to_dist, to_time) with | (_, Hour, _, Second) -> let converted_time = second_element(convert_time (Second, val_) Hour) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) | (_, Second, _, Hour) -> let converted_time = second_element(convert_time (Hour, val_) Second) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) | (_, _, _, _) -> let converted_time = second_element(convert_time (time_unit, val_) to_time) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_unit = fst a in let a_val = snd a in let converted_aSpeed = convert_speed(a_unit, a_val) b_unit in ((fst b_unit, snd b_unit), b_val +. snd converted_aSpeed ) ;; |
let passes_da_vinci t = let rec summation l acc = match l with | [] -> acc | Leaf :: tl -> summation (tl) (acc) | Branch(width, subtree) :: tl -> let subtree_sum = summation (subtree) ((width ** 2.) +. acc) in summation (tl) (subtree_sum) in let rec check l = match l with | [] -> true; | Leaf :: td -> check td | Branch (width, subtree) :: tl -> let check_child = check(subtree) in if ((summation (subtree) (0.) >= width ** 2.) ) then false else if (not(check_child) && (summation (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 :: td -> if hd = cur_el then aux td (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num && cur_el < max_el then aux td (hd,1) (cur_el,cur_num) else if cur_num > max_num && cur_el >= max_el then aux td (cur_el, cur_num+1) (max_el, max_num) else aux td (hd, 1) (max_el, max_num) in match List.sort compare l with | [] -> failwith "list cannot be empty" | hd :: td -> (aux l (hd, 0) (hd, 1)) ;; |
let pair_mode (l: 'a list) : 'a * 'a = let l = List.sort compare l in match l with | [] -> failwith "list cannot be empty" | hd :: td -> let (_ :: no_head) = l in let (_:: no_head) = List.rev(List.rev(no_head)) in let l1 = no_head in let l2 = l1 in mode(List.combine l1 l2) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let unit_from = fst(from_unit,val_) in let init_val = snd(from_unit,val_) in match (unit_from,to_unit) with | (Second,Second) | (Hour,Hour) -> (to_unit, val_) | (Second, Hour) -> (to_unit, init_val /. 3600.) | (Hour,Second) -> (to_unit, init_val *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let unit_from = fst(from_unit,val_) in let init_val = snd(from_unit,val_) in match (unit_from,to_unit) with | (Foot,Foot) | (Meter, Meter) | (Mile, Mile) -> (to_unit, init_val) | (Foot, Meter) -> (to_unit, init_val *. 0.3048) | (Meter, Foot) -> (to_unit, init_val /. 0.3048) | (Foot, Mile) -> (to_unit, init_val /. 5280.) | (Mile, Foot) -> (to_unit, init_val *. 5280.) | (Meter, Mile) -> (to_unit, init_val /. 1609.344) | (Mile, Meter) -> (to_unit, init_val *. 1609.344) ;; let first_element (pair : 'a * 'b) : 'a = let (first, _) = pair in first let second_element ((a, b) : 'a * 'b) : 'b = b;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_unit = first_element(from_unit) in let time_unit = second_element(from_unit) in let to_dist = first_element(to_unit) in let to_time = second_element(to_unit) in match (dist_unit, time_unit,to_dist, to_time) with | (_, Hour, _, Second) -> let converted_time = second_element(convert_time (Second, val_) Hour) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) | (_, Second, _, Hour) -> let converted_time = second_element(convert_time (Hour, val_) Second) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) | (_, _, _, _) -> let converted_time = second_element(convert_time (time_unit, val_) to_time) in let result = second_element(convert_dist (dist_unit, converted_time) to_dist) in (to_unit, result) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_unit = fst a in let a_val = snd a in let converted_aSpeed = convert_speed(a_unit, a_val) b_unit in ((fst b_unit, snd b_unit), b_val +. snd converted_aSpeed ) ;; |
let passes_da_vinci t = let rec summation l acc = match l with | [] -> acc | Leaf :: tl -> summation (tl) (acc) | Branch(width, subtree) :: tl -> let subtree_sum = summation (subtree) ((width ** 2.) +. acc) in summation (tl) (subtree_sum) in let rec check l = match l with | [] -> true; | Leaf :: td -> check td | Branch (width, subtree) :: tl -> let check_child = check(subtree) in if ((summation (subtree) (0.) >= width ** 2.) ) then false else if (not(check_child) && (summation (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 | head :: rest -> let cur_num, max_info = if cur_num > max_num && head <> cur_el then 1, (cur_el, cur_num) else if head = cur_el then cur_num + 1, (max_el, max_num) else 1, (max_el, max_num) in aux rest (head, cur_num) max_info | [] when cur_num > max_num -> cur_el | [] -> max_el in let l = List.sort compare l in let head = List.hd l in let rest = List.tl l in aux rest (head, 1) (head, 1) ;; |
let pair_mode (l: 'a list) : 'a * 'a = let rec helper before pairs l = match l, before with | [], _ -> pairs | head::rest, None -> helper (Some head) pairs rest | head::rest, Some before -> let pairs = (before, head) :: pairs in helper (Some head) pairs rest in let pairs = helper None [] l in mode pairs ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let seconds = 3600. in let to_val_ = match from_unit, to_unit with | Hour, Second -> val_ *. seconds | Second, Hour -> val_ /. seconds | Hour, Hour -> val_ | Second, Second -> val_ in to_unit, to_val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let foot_meters = 0.3048 in let mile_feet = 5280. in let mile_meters = 1609.344 in to_unit, (match from_unit, to_unit with | Mile, Foot -> val_ *. mile_feet | Foot, Mile -> val_ /. mile_feet | Mile, Meter -> val_ *. mile_meters | Meter, Mile -> val_ /. mile_meters | Meter, Foot -> val_ /. foot_meters | Foot, Meter -> val_ *. foot_meters | Mile, Mile -> val_ | Foot, Foot -> val_ | Meter, Meter -> val_) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (td, tt), (fd, ft) = to_unit, from_unit in let (td, ds), (tt, ts) = (convert_dist (fd, val_) td, convert_time (ft, 1.) tt) in let speed_unit = td, tt in let time_unit = ds /. ts in speed_unit, time_unit ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (fst speed_unit), (speed_val *. (convert_time time (snd speed_unit) |> snd)) ;; let rec passes_da_vinci t = let rec squares_of_branch value nodes = (squares_of_nodes nodes) +. (value *. value) and squares_of_nodes = function | Leaf :: rest -> squares_of_nodes rest | Branch (value, nodes) :: rest -> squares_of_branch value nodes +. (squares_of_nodes rest) | [] -> 0. in match t with | Leaf -> true | Branch (value, nodes) -> let flag = List.fold_left (fun acc node -> acc && passes_da_vinci node) true nodes in flag && squares_of_nodes nodes <= (value *. value) ;; |
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 aux tl (hd, 1) (max_el, max_num) in match List.sort compare l with | [] -> raise (Failure "empty") | hd :: tl -> aux tl (hd, 1) (hd, 0) ;; |
let pair_mode (l: 'a list) : 'a * 'a = let rec compute_pair l = match l with | [] -> raise (Failure "empty") | [_] -> raise (Failure "not enough element") | [h1;h2] -> [(h1,h2)] | h1 :: h2 :: tl -> (h1,h2) :: (compute_pair (h2::tl)) in mode (compute_pair 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.) | _ -> (from_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.) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Mile, Meter) -> (Meter, val_ *. (0.3048 *. 5280.)) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mile) -> (Mile, val_ /. (0.3048 *. 5280.)) | _ -> (from_unit, val_) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_unit_dist, from_unit_time) = from_unit in let (to_unit_dist, to_unit_time) = to_unit in let (final_unit_dist, total_dist) = convert_dist (from_unit_dist, val_) to_unit_dist in let (final_unit_time, total_time) = convert_time (from_unit_time, 1.) to_unit_time in ((final_unit_dist, final_unit_time), total_dist /. total_time) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (final_dist_unit, final_time_unit) = speed_unit in let (_, time_val) = convert_time time final_time_unit in (final_dist_unit, speed_val *. time_val) ;; let tree_example = Branch (5., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (4., []) ]) ;; let t1 = Branch (1., [Leaf; Leaf]) ;; let t2 = Leaf;; let t3 = Branch (2., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (5., []) ]) ;; let t4 = Branch (6., [ Branch (3.,[Leaf; Leaf; Leaf]); Branch (2., [Branch (1., [Leaf]); Leaf; Branch (1., [])]); Branch (1., []); Branch (4., [Branch (1., [Leaf]); Branch (2., [Leaf; Leaf])]) ]);; let rec sum_square tree_lst acc = match tree_lst with | [] -> acc | hd :: tl -> sum_square tl (acc +. hd *. hd) ;; let rec traversal (tree_lst: tree list) width_lst = match tree_lst with | [] -> sum_square width_lst 0. | hd :: tl -> if hd = Leaf then traversal tl width_lst else let get_width x = match x with | Leaf -> 0. | Branch (width, _) -> width in traversal tl (width_lst @ [(get_width hd)]) ;; let rec passes_da_vinci t = match t with | Leaf -> true | Branch (width, child) -> let rec helper tree_lst satisfied = match tree_lst with | [] -> satisfied | hd :: tl -> helper tl (passes_da_vinci hd) in (width *. width) >= (traversal child []) && (helper child 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 | [] -> 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 aux tl (hd, 1) (max_el, max_num) in match List.sort compare l with | [] -> raise (Failure "empty") | hd :: tl -> aux tl (hd, 1) (hd, 0) ;; |
let pair_mode (l: 'a list) : 'a * 'a = let rec compute_pair l = match l with | [] -> raise (Failure "empty") | [_] -> raise (Failure "not enough element") | [h1;h2] -> [(h1,h2)] | h1 :: h2 :: tl -> (h1,h2) :: (compute_pair (h2::tl)) in mode (compute_pair 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.) | _ -> (from_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.) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Mile, Meter) -> (Meter, val_ *. (0.3048 *. 5280.)) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mile) -> (Mile, val_ /. (0.3048 *. 5280.)) | _ -> (from_unit, val_) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_unit_dist, from_unit_time) = from_unit in let (to_unit_dist, to_unit_time) = to_unit in let (final_unit_dist, total_dist) = convert_dist (from_unit_dist, val_) to_unit_dist in let (final_unit_time, total_time) = convert_time (from_unit_time, 1.) to_unit_time in ((final_unit_dist, final_unit_time), total_dist /. total_time) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (final_dist_unit, final_time_unit) = speed_unit in let (_, time_val) = convert_time time final_time_unit in (final_dist_unit, speed_val *. time_val) ;; let tree_example = Branch (5., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (4., []) ]) ;; let t1 = Branch (1., [Leaf; Leaf]) ;; let t2 = Leaf;; let t3 = Branch (2., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (5., []) ]) ;; let t4 = Branch (6., [ Branch (3.,[Leaf; Leaf; Leaf]); Branch (2., [Branch (1., [Leaf]); Leaf; Branch (1., [])]); Branch (1., []); Branch (4., [Branch (1., [Leaf]); Branch (2., [Leaf; Leaf])]) ]);; let rec sum_square tree_lst acc = match tree_lst with | [] -> acc | hd :: tl -> sum_square tl (acc +. hd *. hd) ;; let rec traversal (tree_lst: tree list) width_lst = match tree_lst with | [] -> sum_square width_lst 0. | hd :: tl -> if hd = Leaf then traversal tl width_lst else let get_width x = match x with | Leaf -> 0. | Branch (width, _) -> width in traversal tl (width_lst @ [(get_width hd)]) ;; let rec passes_da_vinci t = match t with | Leaf -> true | Branch (width, child) -> let rec check tree_lst satisfied = match tree_lst with | [] -> satisfied | hd :: tl -> check tl (passes_da_vinci hd) in (width *. width) >= (traversal child []) && (check child 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 | [] -> 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 aux tl (hd, 1) (max_el, max_num) in match List.sort compare l with | [] -> raise (Failure "empty") | hd :: tl -> aux tl (hd, 1) (hd, 0) ;; |
let pair_mode (l: 'a list) : 'a * 'a = let rec compute_pair l = match l with | [] -> raise (Failure "empty") | [_] -> raise (Failure "not enough element") | [x1;x2] -> [(x1,x2)] | x1 :: x2 :: tl -> (x1,x2) :: (compute_pair (x2::tl)) in mode (compute_pair 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.) | _ -> (from_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.) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Mile, Meter) -> (Meter, val_ *. (0.3048 *. 5280.)) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mile) -> (Mile, val_ /. (0.3048 *. 5280.)) | _ -> (from_unit, val_) ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_unit_dist, from_unit_time) = from_unit in let (to_unit_dist, to_unit_time) = to_unit in let (final_unit_dist, total_dist) = convert_dist (from_unit_dist, val_) to_unit_dist in let (final_unit_time, total_time) = convert_time (from_unit_time, 1.) to_unit_time in ((final_unit_dist, final_unit_time), total_dist /. total_time) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (_, speed_a_val) = convert_speed a b_unit in (b_unit, speed_a_val +. b_val) ;; |
let passes_da_vinci t = let rec traversal (tree_lst: tree list) width_lst = match tree_lst with | [] -> sum_square width_lst 0. | hd :: tl -> if hd = Leaf then traversal tl width_lst else let update_width l = match l with | Leaf -> 0. | Branch (width, _) -> width in traversal tl (width_lst @ [(update_width hd)]) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if (check subtree) && (traversal subtree [] <= width ** 2.) then check tl else false in check [t] ;; |
let domain () = failwith "List length too short" let domain2 () = failwith "Unit not implemented";; |
let mode (l: 'a list) : 'a = let sorted_list = List.sort compare (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 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 l (List.hd(l), 0) (cur_el, cur_num) else aux l (List.hd(l), 0) (max_el, max_num) ) in if List.length (l) = 0 then domain () else aux sorted_list (List.hd(sorted_list), 0) (List.hd(sorted_list), 0);; |
let pair_mode (l: 'a list) : ('a * 'a) = let copy1 = List.tl (l) in let copy2 = List.rev (List.tl(l)) in let tuple_list = List.combine copy1 copy2 in if List.length (l) < 3 then domain () else mode (tuple_list);; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if snd ((from_unit, val_)) < 0. then domain2 () else match from_unit with | Hour -> if to_unit = Hour then (Hour, val_) else (Second, val_ *. 3600.) | 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 snd ((from_unit, val_)) < 0. then domain2 () else 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.) | Mile -> if to_unit = Mile then (Mile, val_) else if (to_unit = Meter) then (Meter, val_ *. 0.3048 *. 5280.) else (Foot, val_ *. 5280.) | Meter -> if to_unit = Meter then (Meter, val_) else if (to_unit = Foot) then (Foot, val_ /. 0.3048) else (Mile, val_ /. 5280. /. 0.3048);; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if snd ((from_unit, val_)) < 0. then domain2 () else let from_distance_unit = fst (from_unit) in let to_distance_unit = fst (to_unit) in let new_distance = convert_dist (from_distance_unit, val_) to_distance_unit in let from_time_unit = snd (from_unit) in let old_val = snd (new_distance) in let to_time_unit = snd (to_unit) in let new_time = convert_time (to_time_unit, old_val) from_time_unit in ((to_distance_unit, to_time_unit), snd (new_time));; |
let dist_traveled (time_unit, time_val) ((speed_unit, speed_val) : speed_unit value) = let new_time = snd (speed_unit) in let time = convert_time (time_unit, time_val) new_time in (fst(speed_unit), speed_val *. snd(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 | [] -> max_el | x :: xs -> match xs with | [] -> max_el | h :: _ -> if x = h 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_num) else aux xs (h, 1) (max_el, max_num) in let ls = List.sort compare (l) in match ls with | [] -> failwith "Input list too small" | x :: xs -> aux ls (x, 1) (x, 1) ;; |
let pair_mode (l: 'a list) : 'a * 'a = let rec create_tuple_list (l : 'a list) (t_ls: ('a * 'a) list) : ('a * 'a) list = match l with | [] -> [] | x :: xs -> match xs with | [] -> t_ls | h :: _ -> create_tuple_list (xs) ((x, h) :: t_ls) in match l with | [] -> failwith "List too small" | x :: xs -> match xs with | [] -> failwith "List too small" | _ -> let ls = create_tuple_list l [] in mode ls ;; |
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 | Meter -> (Meter, val_) | Foot -> (Foot, val_ /. 0.3048) | Mile -> (Mile, (val_ /. 0.3048) /. 5280.)) | Mile -> (match to_unit with | Mile -> (Mile, val_) | Foot -> (Foot, val_ *. 5280.) | Meter -> (Meter, (val_ *. 5280.) *. 0.3048)) ;; |
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 (_, new_dist) = convert_dist(a, val_) c in let (_, new_val) = convert_time(d, new_dist) b in ((c, d), new_val) ;; |
let dist_traveled ((time_unit, time_val): time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (a,b) = speed_unit in let (_,correct_time) = convert_time (time_unit, time_val) (b) in (a, correct_time *. speed_val) ;; let rec passes_da_vinci t = let rec square_sum t_list sum = match t_list with | [] -> sum | x :: xs -> match x with | Leaf -> square_sum xs sum | Branch(w, _) -> square_sum xs (sum +. (w ** 2.)) in match t with | Leaf -> true | Branch (w, t_l) -> let children_sum = square_sum (t_l) (0.) in if children_sum > (w ** 2.) then false else match t_l with | [] | [Leaf] -> true | x :: xs -> List.for_all passes_da_vinci (t_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 | [] -> begin if cur_num > max_num then cur_el else if cur_num = max_num then if cur_el < max_el then cur_el else max_el else max_el end | head::next -> begin let num_ocr = if cur_el = head then cur_num + 1 else 1 in if (num_ocr >= max_num && head < max_el) || num_ocr > max_num then aux next (head, num_ocr) (head, num_ocr) else aux next (head, num_ocr) (max_el, max_num) end in if List.length l <= 0 then failwith "Empty List" ; aux (List.sort compare l) (List.hd l, 0) (List.hd l, 0) ;; |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "List too short" ; let l1 = List.rev l in let l2 = List.tl l1 in let l3 = List.rev l2 in mode (List.combine l3 (List.tl l)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> if from_unit = Hour then to_unit, val_ *. 3600. else to_unit, val_ | Hour -> if from_unit = Second then to_unit, val_ /. 3600. else to_unit, val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> begin if from_unit = Meter then to_unit, val_ /. 0.3048 else if from_unit = Mile then to_unit, val_ *. 5280. else to_unit, val_ end | Meter -> begin if from_unit = Foot then to_unit, val_ *. 0.3048 else if from_unit = Mile then to_unit, val_ *. 1609.344 else to_unit, val_ end | Mile -> begin if from_unit = Meter then to_unit, val_ /. 1609.344 else if from_unit = Foot then to_unit, val_ /. 5280. else to_unit, val_ end ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distance_conv = convert_dist ((fst from_unit), val_) (fst to_unit) in let time_conv = convert_time ((snd to_unit), (snd distance_conv)) (snd from_unit) in (to_unit, (snd time_conv)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let speed_conv = convert_speed a b_unit in (b_unit, (snd speed_conv) +. b_val) ;; |
let passes_da_vinci t = traverse 0 t = 0 ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.