text
stringlengths
0
601k
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;;
let passes_da_vinci t = let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && (squaredSumSubtrees (width, subtree) <= width)) then check tl else false in check [t] ;;
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 | [] -> if cur_num > max_num then cur_el else if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;;
let passes_da_vinci t = let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && (squaredSumSubtrees (width, subtree) <= width)) then check tl else false in check [t] ;;
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 | [] -> if cur_num > max_num then cur_el else if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;;
let passes_da_vinci t = let acc = 0. in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && (squaredSumSubtrees acc (width, subtree) <= width)) then check tl else false in check [t] ;;
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 | [] -> if cur_num > max_num then cur_el else if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;;
let passes_da_vinci t = let acc = 0. in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && (squaredSumSubtrees acc (width, subtree) <= width)) then check tl else false in check [t] ;;
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 | [] -> if cur_num > max_num then cur_el else if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;;
let passes_da_vinci t = let acc = 0. in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && ((squaredSumSubtrees acc subtree) <= width)) then check tl else false in check [t] ;;
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 | [] -> if cur_num > max_num then cur_el else if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;;
let passes_da_vinci t = let acc = 0. in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && ((squaredSumSubtrees acc subtree) <= (width *. width))) 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 | 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 a...
let pair_mode (l: 'a list) : 'a * 'a = let rec get_tupples l last_el tup_l = match l with | [] -> mode tup_l | x::xs -> get_tupples xs x ((last_el, x)::tup_l) in match l with | [] -> failwith "No mode" | x::xs -> if xs = [] then failwith "No mode" else get_tupples xs x [] ;;
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 | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. 0.3048 /. 5280.) | Mile, Meter -> (Meter, val_ *. 5280. *. 0.3048) | Mile, Foot -> (Foot, val_ *. 5280.) | Foot, Mile -> (Mile, val_ /....
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (a,b), v, (c,d) = from_unit, val_, to_unit in ((c,d), ((snd (convert_dist (a, v) c)) /. (snd (convert_time (b, 1.0) d)))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let ((a,b), v1), (c,d), v2 = a, b_unit, b_val in ((c,d), v2 +. snd (convert_speed ((a,b), v1) (c,d))) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch(x,y) -> if x*.x >= (square_lst_tree y 0.) then func y else false;;
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 a...
let pair_mode (l: 'a list) : 'a * 'a = let rec get_tupples l last_el tup_l = match l with | [] -> mode tup_l | x::xs -> get_tupples xs x ((last_el, x)::tup_l) in match l with | [] -> failwith "No mode" | x::xs -> if xs = [] then failwith "No mode" else get_tupples xs x [] ;;
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 | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. 0.3048 /. 5280.) | Mile, Meter -> (Meter, val_ *. 5280. *. 0.3048) | Mile, Foot -> (Foot, val_ *. 5280.) | Foot, Mile -> (Mile, val_ /....
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (a,b), v, (c,d) = from_unit, val_, to_unit in ((c,d), ((snd (convert_dist (a, v) c)) /. (snd (convert_time (b, 1.0) d)))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let ((a,b), v1), (c,d), v2 = a, b_unit, b_val in ((c,d), v2 +. snd (convert_speed ((a,b), v1) (c,d))) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch(x,y) -> if x*.x >= (square_lst_tree y 0.) then func y else false;;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | hd :: tl -> if hd = cur_el then aux tl (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux tl (hd, 1) (cur_el, cur_num) el...
let pair_mode (l: 'a list) : 'a * 'a = if (List.length l) < 2 then failwith "This list is invalid." else let l1 = remove_hd l in let l2 = List.rev (remove_hd (List.rev l)) in mode (List.combine l2 l1) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit = Hour then (Hour, val_ /. 3600.) else (Second, val_) | Hour -> if to_unit = Second then (Second, val_ *. 3600.) else (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> if to_unit = Meter then (Meter, val_ *. 0.3048) else if to_unit = Mile then (Mile, val_ /. 5280.) else (Foot, val_) | Meter -> if to_unit = Foot then (Foot, val_ /. 0.3048) else if to_unit = Mile then (Mile...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let final_dist = fst (to_unit) in let final_time = snd (to_unit) in let init_dist = fst (fst (from_unit, val_)) in let init_time = snd (fst (from_unit, val_)) in let final_value = (snd (convert_dist (init_dist, val_) final_dist)) /. (...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let new_a = convert_speed a b_unit in (fst (b_unit, b_val), snd (new_a) +. snd (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 ((sq width) +. acc) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && ((sum_ subtree 0. <= (sq widt...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | hd :: tl -> if hd = cur_el then aux tl (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux tl (hd, 1) (cur_el, cur_num) el...
let pair_mode (l: 'a list) : 'a * 'a = if (List.length l) < 2 then failwith "This list is invalid." else let l1 = remove_hd l in let l2 = List.rev (remove_hd (List.rev l)) in mode (List.combine l2 l1) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit = Hour then (Hour, val_ /. 3600.) else (Second, val_) | Hour -> if to_unit = Second then (Second, val_ *. 3600.) else (Hour, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> if to_unit = Meter then (Meter, val_ *. 0.3048) else if to_unit = Mile then (Mile, val_ /. 5280.) else (Foot, val_) | Meter -> if to_unit = Foot then (Foot, val_ /. 0.3048) else if to_unit = Mile then (Mile...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let final_dist = fst (to_unit) in let final_time = snd (to_unit) in let init_dist = fst (fst (from_unit, val_)) in let init_time = snd (fst (from_unit, val_)) in let final_value = (snd (convert_dist (init_dist, val_) final_dist)) /. (...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let new_a = convert_speed a b_unit in (fst (b_unit, b_val), snd (new_a) +. snd (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 ((sq width) +. acc) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && ((sum_ subtree 0. <= (sq widt...
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 match cur_num > max_num with | true -> cur_el | false -> max_el end | first::tl -> let new_cur_num, new_max_el, new_max_num = match first = cur_el with | true -> (cur_num + 1, max_el, ma...
let pair_mode (l: 'a list) : 'a * 'a = List.fold_right (fun item (pairs, after) -> match after with | None -> pairs, Some item | Some value -> let pairs = (item, value) :: pairs in pairs, (Some item)) l ([], None) |> fst |> mode ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let value = 3600. in if from_unit = Hour && to_unit = Second then to_unit, val_ *. value else if from_unit = Second && to_unit = Hour then to_unit, val_ /. value else to_unit, val_ ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let mile_to_foot v = v *. 5280. in let foot_to_mile v = v /. 5280. in let meter_to_mile v = v /. 1609.344 in let mile_to_meter v = v *. 1609.344 in let meter_to_foot v = val_ /. 0.3048 in let foot_to_meter v = val_ *. 0.3048 in match fro...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist, time = from_unit in let dist', time' = to_unit in let converted_dist = convert_dist (dist, val_) dist' in let converted_time = convert_time (time, 1.) time' in (fst converted_dist, fst converted_time), (snd converted_dist /....
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let dist = snd (convert_time time (snd speed_unit)) *. speed_val in (fst speed_unit), dist ;; let rec passes_da_vinci t = match t with | Leaf -> true | Branch (num, children) -> let children_values = List.fold_left (fun acc i -> mat...
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 match cur_num > max_num with | true -> cur_el | false -> max_el end | first::tl -> let new_cur_num, new_max_el, new_max_num = match first = cur_el with | true -> (cur_num + 1, max_el, ma...
let pair_mode (l: 'a list) : 'a * 'a = List.fold_right (fun item (pairs, after) -> match after with | None -> pairs, Some item | Some value -> let pairs = (item, value) :: pairs in pairs, (Some item)) l ([], None) |> fst |> mode ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let value = 3600. in if from_unit = Hour && to_unit = Second then to_unit, val_ *. value else if from_unit = Second && to_unit = Hour then to_unit, val_ /. value else to_unit, val_ ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let mile_to_foot v = v *. 5280. in let foot_to_mile v = v /. 5280. in let meter_to_mile v = v /. 1609.344 in let mile_to_meter v = v *. 1609.344 in let meter_to_foot v = val_ /. 0.3048 in let foot_to_meter v = val_ *. 0.3048 in match fro...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist, time = from_unit in let dist', time' = to_unit in let converted_dist = convert_dist (dist, val_) dist' in let converted_time = convert_time (time, 1.) time' in (fst converted_dist, fst converted_time), (snd converted_dist /....
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let dist = snd (convert_time time (snd speed_unit)) *. speed_val in (fst speed_unit), dist ;; let rec passes_da_vinci t = let rec tree_list_sum = function | [] -> 0. | cur :: left_branches -> (tree_list_sum left_branches) +. (if cur...
let mode (l: 'a list) : 'a = let l= List.sort compare l in let head l:'a = match l with |[] -> failwith "Undefined input" |el::li -> el in let rec aux (l: 'a list) ((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 |el::li -> if el=cur_el then...
let pair_mode (l: 'a list) : 'a * 'a = if [] = l then failwith "Undefined input" else if (List.length l)<2 then failwith "Undefined input" else let rec shift (l: 'a list) (z: 'a list) (i:int)= if 0< i then shift l (List.append [List.nth l i] z) (i-1) else mode (List.combine l (List.append z [List.nth l 0])) in shift l ...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,val_) with |(Second, _ ) -> (match to_unit with |Hour -> (Hour, val_/.3600.0) |Second -> (Second, val_)) |(Hour, _ )->(match to_unit with |Hour -> (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_) with |(Foot, _ ) -> (match to_unit with |Foot -> (Foot, val_) |Meter -> (Meter, val_*.0.3048) |Mile -> (Mile, val_/.5280.0) ) |(Meter, _ )->(match to_unit with |Foot -> (Foot, val_/.0.3048) |Meter -> (Meter, val_) ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((f, a), k )= (from_unit, val_)in let (c, b)= to_unit in let (t_unit, val_T)=(convert_time (a,1.0) b) in let (d_unit, val_d)=(convert_dist (f,val_) c) in (to_unit, val_d /. (val_T) ) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (un, dist)= convert_speed (a) b_unit in let (un2, dist2)= (b_unit, b_val) in (un2,(dist2)+.(dist)) ;;
let passes_da_vinci t = let rec checker l= match l with | [] -> true | Leaf::tl-> checker tl | Branch (witdth,subtree)::tl -> if not (checker (subtree) && witdth*.witdth >= (sum_sq subtree 0.0)) then false else checker tl in checker [t] ;;
let mode (l: 'a list) : 'a = let l= List.sort compare l in let head l:'a = match l with |[] -> failwith "Undefined input" |el::li -> el in let rec aux (l: 'a list) ((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 |el::li -> if el=cur_el then...
let pair_mode (l: 'a list) : 'a * 'a = if [] = l then failwith "Undefined input" else if (List.length l)<2 then failwith "Undefined input" else let rec shift (l: 'a list) (z: 'a list) (i:int)= if 0< i then shift l (List.append [List.nth l i] z) (i-1) else mode (List.combine l (List.append z [List.nth l 0])) in shift l ...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,val_) with |(Second, _ ) -> (match to_unit with |Hour -> (Hour, val_/.3600.0) |Second -> (Second, val_)) |(Hour, _ )->(match to_unit with |Hour -> (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_) with |(Foot, _ ) -> (match to_unit with |Foot -> (Foot, val_) |Meter -> (Meter, val_*.0.3048) |Mile -> (Mile, val_/.5280.0) ) |(Meter, _ )->(match to_unit with |Foot -> (Foot, val_/.0.3048) |Meter -> (Meter, val_) ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((f, a), k )= (from_unit, val_)in let (c, b)= to_unit in let (t_unit, val_T)=(convert_time (a,1.0) b) in let (d_unit, val_d)=(convert_dist (f,val_) c) in (to_unit, val_d /. (val_T) ) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (un, dist)= convert_speed (a) b_unit in let (un2, dist2)= (b_unit, b_val) in (un2,(dist2)+.(dist)) ;;
let passes_da_vinci t = let rec checker l= match l with | [] -> true | Leaf::tl-> checker tl | Branch (witdth,subtree)::tl -> if not (checker (subtree) && witdth*.witdth >= (sum_sq subtree 0.0)) then false else checker tl in checker [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 (x, 1 + cur_num) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1) (cur_el, cur_num) else aux x...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "List too small." else match l with | [] -> failwith "List too small." | _::l2 -> match List.rev l with | _::ls -> mode (List.combine (List.rev ls) l2) | [] -> failwith "List too small." ;;
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) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Mile, Meter) -> (Meter, val_ *. 5280....
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((dist_1, time_1), (dist_2, time_2)) = (from_unit, to_unit) in let ((d_unit, d), (t_unit, t)) = ((convert_dist (dist_1, val_) dist_2), (convert_time (time_1, 1.) time_2)) in ((d_unit, t_unit), d /. t) ;;