text
stringlengths
0
601k
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = ((b_unit), b_val +. snd(convert_speed(a)(b_unit))) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> 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.)) <= wid...
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 if cur_num = max_num && max_el > cur_el 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_n...
let pair_mode (l: 'a list) : 'a * 'a = let remove_first l = match l with | [] -> [] | h :: t -> t in match l with | [] -> failwith "Undefined input." | _ -> let l3 = remove_first l in let l4 = remove_first (List.rev l) in let l5 = List.rev l4 in let list_tuple = List.combine l5 l3 in mode list_tuple ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> if from_unit = Second then (from_unit, val_) else (from_unit, val_*.3600.) | Hour -> if from_unit = Second then (from_unit, val_/.3600.) else (from_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> if from_unit = Meter then (from_unit, val_/.0.3048) else if from_unit = Mile then (from_unit, val_*.5280.) else (from_unit, val_) | Meter -> if from_unit = Foot then (from_unit, val_*.0.3048) else if from_uni...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let speed_no_time = convert_dist ((fst from_unit), val_) (fst to_unit) in let time_no_speed = convert_time ((snd from_unit), 1.) (snd to_unit) in (from_unit, snd speed_no_time/. snd time_no_speed) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (fst speed_unit, snd time*. snd (convert_speed (speed_unit, speed_val) (fst speed_unit, fst time))) ;; let tree4 = Branch (5., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (4., [])]);; let tree5 = Branch(4., [Leaf]);; let tree6 =...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el |hd :: tl -> if hd = cur_el && cur_num+1 <= max_num then aux tl (hd, cur_num+1) (max_el, max_num) else if hd = cur_el && cur_num+1 > max_num then aux tl (hd,cur_num+1) (hd,cur_num+1) el...
let pair_mode (l: 'a list) : 'a * 'a = if (List.length l) < 2 then failwith "unvalid input" else if (List.length l)=2 then ((List.nth l 0),(List.nth l 1)) else let original_l = l in mode (List.combine (List.rev (List.tl (List.rev original_l))) (List.tl l)) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then failwith "unvalid input" else match from_unit, to_unit with |Second, Second | Hour, Hour -> to_unit, val_ |Second, Hour -> Hour, val_/.3600. |Hour, Second -> Second, val_*.3600. ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if val_ < 0. then failwith "unvalid input" else match (from_unit, to_unit) with |Foot, Foot | Meter, Meter | Mile, Mile -> to_unit, val_ |Foot, Meter -> Meter, val_*.0.3048 |Meter, Foot -> Foot, val_/.0.3048 |Foot, Mile -> Mile, val_/.52...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (to_unit,snd(convert_dist (fst from_unit, snd (convert_time (snd to_unit, val_) (snd from_unit))) (fst to_unit))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, snd((convert_speed a b_unit))+.b_val) ;;
let passes_da_vinci t = let rec check l = match l with |[] -> true |Leaf :: tl -> check tl |Branch (val_, sub_tree) :: tl -> if (not (check sub_tree) || (val_**2.) < (summation sub_tree 0.)) then false else check tl in check [t] ;;
let mode (l: 'a list) : 'a = let l = List.sort compare l in match l with | [] -> failwith "Empty list" | hd:: _ -> let rec aux l ((cur_el,cur_num) : ('a * int)) ((max_el,max_num) : ('a * int)) = match l with | x::xs -> ( if x = cur_el then ( if (cur_num + 1) > max_num then( aux xs (x, (cur_num + 1)) ( x, (cur_num+1)) )...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Invalid list" else match l with |_ -> mode (List.combine (List.rev (List.tl (List.rev l))) (List.tl l) ) | [] -> failwith "Empty list" ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Hour -> ( match to_unit with | Second -> from_unit, val_ *. 3600. | Hour -> from_unit , val_ ) | Second -> ( match to_unit with | Second -> from_unit, val_ | Hour -> from_unit, 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 -> to_unit, val_ *. 0.3048 | Mile -> to_unit, val_ /. 5280. |Foot -> to_unit, val_ ) | Meter -> ( match to_unit with | Foot -> to_unit, val_ /. 0.3048 | Mile -> to_unit, val_ /....
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit with | (_, Second) -> (match to_unit with |(_, Second) ->from_unit, snd( convert_dist (fst(from_unit) , (val_)) (fst(to_unit))) |( _, Hour) -> from_unit, snd(convert_dist (fst(from_unit), val_) (fst(to_unit)) )*. getTi...
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 current = (match l with | [] -> current | Leaf :: tl -> summation tl current | Branch (width, subtree) :: tl -> summation tl (current +. (width *. width))) in let rec check t = match t with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> (if (not (che...
let mode (l: 'a list) : 'a = let l = List.sort compare l in match l with | [] -> failwith "Empty list" | hd:: _ -> let rec aux l ((cur_el,cur_num) : ('a * int)) ((max_el,max_num) : ('a * int)) = match l with | x::xs -> ( if x = cur_el then ( if (cur_num + 1) > max_num then( aux xs (x, (cur_num + 1)) ( x, (cur_num+1)) )...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Invalid list" else match l with |_ -> mode (List.combine (List.rev (List.tl (List.rev l))) (List.tl l) ) | [] -> failwith "Empty list" ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Hour -> ( match to_unit with | Second -> from_unit, val_ *. 3600. | Hour -> from_unit , val_ ) | Second -> ( match to_unit with | Second -> from_unit, val_ | Hour -> from_unit, 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 -> to_unit, val_ *. 0.3048 | Mile -> to_unit, val_ /. 5280. |Foot -> to_unit, val_ ) | Meter -> ( match to_unit with | Foot -> to_unit, val_ /. 0.3048 | Mile -> to_unit, val_ /....
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit with | (_, Second) -> (match to_unit with |(_, Second) ->from_unit, snd( convert_dist (fst(from_unit) , (val_)) (fst(to_unit))) |( _, Hour) -> from_unit, snd(convert_dist (fst(from_unit), val_) (fst(to_unit)) )*. snd(c...
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 current = (match l with | [] -> current | Leaf :: tl -> summation tl current | Branch (width, subtree) :: tl -> summation tl (current +. (width *. width))) in let rec check t = match t with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> (if (not (che...
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 (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1) (cur_el, cur_num) e...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "empty list, no pair_mode" | _ -> mode (List.combine (List.rev (List.tl (List.rev l))) (List.tl l)) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (to_unit, (val_ /. 3600.)) | (Hour, Second) -> (to_unit, (val_ *. 3600.)) | _ -> (to_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Mile) -> (to_unit, (val_ /. 5280.)) | (Foot, Meter) -> (to_unit, (val_ *. 0.3048)) | (Mile, Foot) -> (to_unit, val_ *. 5280.) | (Mile, Meter) -> (to_unit, val_ *. 1609.344) | (Meter, Mile) -> (to_...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (to_unit, snd (convert_time ((snd to_unit), (snd (convert_dist ((fst from_unit), val_) (fst to_unit)))) (snd from_unit))) ;;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, ((snd (convert_speed a b_unit)) +. b_val)) ;;
let passes_da_vinci t = let rec traverse t = match t with | [] -> true | x :: xs -> ( match x with | Leaf -> traverse xs | Branch (width, children) -> if (width *. width) < (recurse children) then false else traverse children ) in match t with | Leaf -> true | Branch (width, children) -> if (width *. width) < (recurse ...
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | h::t -> if (h=cur_el) then if (cur_num+1 > max_num) then aux t (cur_el, cur_num+1) (cur_el, cur_num+1) else aux t (cur_el, cur_num+1) (max_el, max_num) else aux t (h, 1) (max_el, max_...
let pair_mode (l: 'a list) : 'a * 'a = mode (List.combine (List.rev (List.tl (List.rev l))) (List.tl l)) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (match to_unit with | Second -> (Second, val_) | Hour -> (Hour, val_/.3600.)) | Hour -> (match to_unit with | Second -> (Second, val_*.3600.) | Hour -> (Hour, val_)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> (match to_unit with | Foot -> (Foot, val_) | Meter -> (Meter, val_*.0.3048) | Mile -> (Mile, val_/.5280.)) | Meter -> (match to_unit with | Foot -> (Foot, val_/.0.3048) | Meter -> (Meter, val_) | Mile -> (M...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit with | (Meter, Second) -> (match to_unit with | (Meter, Second) -> ((Meter, Second), val_) | (Meter, Hour) -> ((Meter, Hour), val_*.3600.) | (Foot, Second) -> ((Foot, Second), val_*.(1./.0.3048)) | (Mile, Second) -> ((...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (x, y) = time in let (a, b) = speed_unit in let (_, lu) = convert_time (x, y) b in (a, (speed_val *. lu)) ;; let rec helper l acc = match l with | [] -> acc | Leaf::t -> helper t acc | Branch (value, list)::t -> helper t ((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 |[] -> max_el |x :: xs -> if(x = cur_el) then if(cur_num+1 > max_num) then aux xs (cur_el, cur_num+1) (cur_el, cur_num+1) else if (cur_num+1 = max_num && cur_el < max_el) then aux xs (cur_el, cur_num+...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Undefined Input" else let rec tupleListBuilder (l: 'a list) (newList: ('a *'a) list) (cur_el: 'a) = match l with |[] -> newList |head :: tail -> tupleListBuilder tail (newList @ [(cur_el, head)]) head in match l with | [] -> failwith "Undefined ...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with |Second -> (match to_unit with |Second -> (to_unit, val_) |Hour -> (to_unit, val_/.3600.) |_ -> failwith "Undefined Input" ) |Hour -> (match to_unit with |Second -> (to_unit, (val_*.3600.)) |Hour -> (to_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 |Foot -> (to_unit, val_) |Meter -> (to_unit, val_*.0.3048) |Mile -> (to_unit, val_/.5280.) |_ -> failwith "Undefined Input" ) |Meter -> (match to_unit with |Meter -> (to_unit, val_) |Foot...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit with |(Meter, Second) -> (match to_unit with |(Meter, Second) -> (Meter, Second), snd(convert_dist (Meter, val_) Meter) /. snd(convert_time (Second, 1.) Second) |(Meter, Hour) -> (Meter, Hour), snd(convert_dist (Meter,...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = ((b_unit), (b_val +. snd(convert_speed ((fst (fst a), snd (fst a)), snd a) (b_unit)))) ;;
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> acc +. sum_ tl acc | Branch (width, subtree) :: tl -> acc +. (width*.width) +. sum_ tl acc in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if((check subtree) && (sum_ subtree ...
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 | head :: tail -> if head = cur_el then aux tail (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux tail (head, 1) (cur_el, c...
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "error" else let (_ :: no_front) = l in let (_ :: no_back) = List.rev l in let l1 = List.rev no_back in let tupleList = List.combine l1 no_front in mode tupleList ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | (Hour, Hour) -> (from_unit, val_) | (Hour, Second) -> (Second, val_ *. 3600.) | (Second, Hour) -> (Hour, val_ /. 3600.) | (Second, Second) -> (from_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | (Foot, Foot) -> (from_unit, val_) | (Meter, Meter) -> (from_unit, val_) | (Mile, Mile) -> (from_unit, val_) | (Foot, Meter) -> (Meter, val_ *. 0.3048) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mi...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let firstDistance = fst(from_unit) in let secondDistance = fst(to_unit) in let firstTime = snd(from_unit) in let secondTime = snd(to_unit) in let (_,distance) = convert_dist (firstDistance, val_) secondDistance in let (_,time) = conve...
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 (_,speed) = convert_speed (a_unit, a_val) b_unit in (b_unit, b_val +. speed) ;;
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 (width ** 2. +. acc) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && (sum_ subtree 0. <= width **...
let mode (l: 'a list) : 'a = let rec aux (lst: 'a list) ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match lst with | [] -> if cur_num > max_num then cur_el else max_el | head::tail when head = cur_el -> aux tail (cur_el, cur_num + 1) (max_el, max_num) | head::tail when cur_num > max_num -> aux tail ...
let pair_mode (l: 'a list) : 'a * 'a = let rec squash l : (('a * 'a) list) = match l with | [] -> [] | x::xs when xs = [] -> [] | x::xs -> (List.nth l 0, List.nth l 1) :: squash xs in match l with | [] -> failwith "List is too short!" | x :: xs when xs = [] -> failwith "List is too short!" | _ -> mode (squash l) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second when to_unit = Hour -> (to_unit, (val_/.3600.)) | Hour when to_unit = Second -> (to_unit, (val_*.3600.)) | _ -> (to_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot when to_unit = Meter -> (to_unit, 0.3048 *. val_) | Foot when to_unit = Mile -> (to_unit, (1./.5280.) *. val_) | Meter when to_unit = Foot -> (to_unit, (1./.0.3048) *. val_) | Meter when to_unit = Mile -> (to_...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_dist, from_time) = from_unit in ( let (to_dist, to_time) = to_unit in ( let (u1, value1) = convert_dist (from_dist, val_) to_dist in ( let (u2, value2) = convert_time ((opposite from_time), value1) (opposite to_time) in (to_...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let ((a_dist_unit, a_time_unit), a_val) = a in ( let ((b_dist_unit, b_time_unit), converted_a_val) = convert_speed ((a_dist_unit, a_time_unit), a_val) b_unit in ( (b_unit, converted_a_val +. b_val) ) ) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch (thickness, branches) -> thickness ** 2. >= add_branch_thickness branches ;;
let mode (l: 'a list) : 'a = let rec aux (lst: 'a list) ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match lst with | [] -> if cur_num > max_num then cur_el else max_el | head::tail when head = cur_el -> aux tail (cur_el, cur_num + 1) (max_el, max_num) | head::tail when cur_num > max_num -> aux tail ...
let pair_mode (l: 'a list) : 'a * 'a = let rec squash l : (('a * 'a) list) = match l with | [] -> [] | x::xs when xs = [] -> [] | x::xs -> (List.nth l 0, List.nth l 1) :: squash xs in match l with | [] -> failwith "List is too short!" | x :: xs when xs = [] -> failwith "List is too short!" | _ -> mode (squash l) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second when to_unit = Hour -> (to_unit, (val_/.3600.)) | Hour when to_unit = Second -> (to_unit, (val_*.3600.)) | _ -> (to_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot when to_unit = Meter -> (to_unit, 0.3048 *. val_) | Foot when to_unit = Mile -> (to_unit, (1./.5280.) *. val_) | Meter when to_unit = Foot -> (to_unit, (1./.0.3048) *. val_) | Meter when to_unit = Mile -> (to_...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_dist, from_time) = from_unit in ( let (to_dist, to_time) = to_unit in ( let (u1, value1) = convert_dist (from_dist, val_) to_dist in ( let (u2, value2) = convert_time ((opposite from_time), value1) (opposite to_time) in (to_...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let ((a_dist_unit, a_time_unit), a_val) = a in ( let ((b_dist_unit, b_time_unit), converted_a_val) = convert_speed ((a_dist_unit, a_time_unit), a_val) b_unit in ( (b_unit, converted_a_val +. b_val) ) ) ;;
let passes_da_vinci t = match t with | Leaf -> true | Branch (thickness, branches) -> if thickness ** 2. >= add_branch_thickness branches then passes_da_vinci_children branches else false ;;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = if (List.length l) = 0 then max_el else ( let next_el = List.hd l in let next_num = if cur_el = next_el then cur_num + 1 else 1 in if next_num > max_num then aux (List.tl l) (next_el, next_num) (next_el, next_num)...
let pair_mode (l: 'a list) : 'a * 'a = let get_pairs (i: int) (a: 'a) : 'a * 'a = if i == (List.length l) - 1 then (a, a) else let snd = List.nth l (i+1) in (a, snd) in if (List.length l) <= 1 then failwith "List less or equal to 1 element" else mode (List.tl (List.rev (List.mapi get_pairs l))) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = (to_unit, (match (from_unit, to_unit) with | (Second, Hour) -> val_ /. 3600. | (Hour, Second) -> val_ *. 3600. | _ -> val_)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = (to_unit, (match (from_unit, to_unit) with | (Foot, Meter) -> val_ *. 0.3048 | (Mile, Foot) -> val_ *. 5280. | (Meter, Foot) -> val_ /. 0.3048 | (Foot, Mile) -> val_ /. 5280. | (Mile, Meter) -> val_ *. 5280. *. 0.3048 | (Meter, Mile) -> ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let from_dist_unit = fst from_unit in let from_time_unit = snd from_unit in let to_dist_unit = fst to_unit in let to_time_unit = snd to_unit in if from_unit = to_unit then (to_unit, val_) else (to_unit, 1. /. (snd (convert_time (from_...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let converted_a_val = snd (convert_speed a b_unit) in (b_unit, converted_a_val +. b_val) ;;
let passes_da_vinci t = let rec sum_sq l = match l with | [] -> 0. | Leaf :: _ -> sum_sq (List.tl l) | Branch (width, _) :: _ -> width *. width +. sum_sq (List.tl l) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> width *. width >= (sum_sq subtree) && check sub...
let getfirst(a, _) = a;; let getsecond(_, b) = b;;
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 (compare cur_num max_num) > 0 then cur_el else max_el | x::xs -> if (compare cur_el x) = 0 then aux xs (cur_el, cur_num + 1) (max_el, max_num) else if (compare cur_num max_num) > 0 && (comp...
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (x: 'a list) (y: 'a list) l = match l with |[] -> failwith "" | b::[] -> mode (List.combine (x) (y @ [b])) | b::bs -> aux (x @ [b]) (y @ [b]) bs in match l with | [] -> failwith "" | x::xs -> aux [x] [] xs ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let first = getfirst (from_unit, val_) in let second = getsecond (from_unit, val_) in if first = to_unit then (from_unit, second) else if to_unit = Hour then (Hour, second *. (1.0/.3600.0)) else (Second, second *. 3600.0) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let first = getfirst (from_unit, val_) in let second = getsecond (from_unit, val_) in if first = to_unit then (from_unit, second) else if first = Foot then match to_unit with | Meter -> (Meter, second *. 0.3048) | Mile -> (Mile, second *...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist,from_time),(to_dist,to_time)) = (from_unit, to_unit) in let (dist, dist_val) = convert_dist (from_dist, val_) to_dist in let (time, time_val) = convert_time (from_time, 1.) to_time in ((dist, time), (dist_val /. time_v...
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 +. getsecond value) ;;
let passes_da_vinci (t : tree) : bool = let rec auxu (x: float) (y: 'a list) = match y with | [] -> true | Leaf :: ys -> auxu (x) (ys) | Branch (widthx, subtree) :: ys -> let width = x *. x in let children = (getneighbours (y) 0.0) in if (compare width children) < 0 then false else let first = auxu (widthx) (subtree) i...
let getfirst(a, _) = a;; let getsecond(_, b) = b;;
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 (compare cur_num max_num) > 0 then cur_el else max_el | x::xs -> if (compare cur_el x) = 0 then aux xs (cur_el, cur_num + 1) (max_el, max_num) else if (compare cur_num max_num) > 0 && (comp...
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (x: 'a list) (y: 'a list) l = match l with |[] -> failwith "Input Error" | b::[] -> mode (List.combine (x) (y @ [b])) | b::bs -> aux (x @ [b]) (y @ [b]) bs in match l with | [] -> failwith "Input Error" | x::xs -> aux [x] [] xs ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let first = getfirst (from_unit, val_) in let second = getsecond (from_unit, val_) in if first = to_unit then (from_unit, second) else if to_unit = Hour then (Hour, second *. (1.0/.3600.0)) else (Second, second *. 3600.0) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let first = getfirst (from_unit, val_) in let second = getsecond (from_unit, val_) in if first = to_unit then (from_unit, second) else if first = Foot then match to_unit with | Meter -> (Meter, second *. 0.3048) | Mile -> (Mile, second *...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_distance, from_time),(to_distance, to_time)) = (from_unit, to_unit) in let (distance, dist_value) = convert_dist (from_distance, val_) to_distance in let (time, time_value) = convert_time (from_time, 1.) to_time in ((distan...
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 +. getsecond value) ;;
let passes_da_vinci (t : tree) : bool = let rec auxu (x: float) (y: 'a list) = match y with | [] -> true | Leaf :: ys -> auxu (x) (ys) | Branch (widthx, subtree) :: ys -> let width = x *. x in let children = (getneighbours (y) 0.0) in if (compare width children) < 0 then false else let first = auxu (widthx) (subtree) i...
let getfirst(a, _) = a;; let getsecond(_, b) = b;;
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 (compare cur_num max_num) > 0 then cur_el else max_el | x::xs -> if (compare cur_el x) = 0 then aux xs (cur_el, cur_num + 1) (max_el, max_num) else if (compare cur_num max_num) > 0 && (comp...
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (x: 'a list) (y: 'a list) l = match l with |[] -> failwith "Input Error" | b::[] -> mode (List.combine (x) (y @ [b])) | b::bs -> aux (x @ [b]) (y @ [b]) bs in match l with | [] -> failwith "Input Error" | x::xs -> aux [x] [] xs ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let first = getfirst (from_unit, val_) in let second = getsecond (from_unit, val_) in if first = to_unit then (from_unit, second) else if to_unit = Hour then (Hour, second *. (1.0/.3600.0)) else (Second, second *. 3600.0) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let first = getfirst (from_unit, val_) in let second = getsecond (from_unit, val_) in if first = to_unit then (from_unit, second) else if first = Foot then match to_unit with | Meter -> (Meter, second *. 0.3048) | Mile -> (Mile, second *...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_distance, from_time),(to_distance, to_time)) = (from_unit, to_unit) in let (distance, dist_value) = convert_dist (from_distance, val_) to_distance in let (time, time_value) = convert_time (from_time, 1.) to_time in ((distan...
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 +. getsecond value) ;;