text stringlengths 0 601k |
|---|
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let from_unit_dist = fst from_unit in let from_unit_time = snd from_unit in let to_unit_dist = fst to_unit in let to_unit_time = snd to_unit in let (new_unit_dist,value1) = convert_dist (from_unit_dist, val_) to_unit_dist in if from_u... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (new_unit, value1) = convert_speed a b_unit in (b_unit, (b_val +. value1)) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> (sum_ tl acc) | Branch (width, subtree) :: tl -> sum_ tl (acc+.(width *. width)) in let rec check l = match l with | [] -> true | Leaf :: tl -> (check tl) | Branch (width, subtree) :: tl -> if sum_ subtree 0. > (width *. width) then f... |
let mode (l: 'a list) : 'a = 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 | 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,... |
let pair_mode (l: 'a list) : 'a * 'a = let rec pairer l : ('a * 'a) list = match l with | [] -> [] | x :: y :: xs -> (x,y) :: pairer (y :: xs) | _ :: [] -> [] in match l with | [] -> failwith "Empty List" | [_] -> failwith "List too small" | _ -> mode (pairer 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.) | Second,Second -> (Second, val_) | Hour,Second -> (Second, val_ *. 3600.) | 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,Meter -> (Meter, val_ *. 0.3048) | Foot,Mile -> (Mile, val_ /. 5280.) | Foot,Foot -> (Foot, val_) | Meter,Foot -> (Foot, val_ /. 0.3048) | Meter,Mile -> (Mile, val_ /. 1609.344) | Meter,Meter -> (Meter... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let tima = convert_time (snd to_unit, val_) (snd from_unit) in (to_unit,snd (convert_dist (fst from_unit, snd tima) (fst to_unit)) ) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let speed1 = convert_speed (fst a, snd a) (b_unit) in (b_unit, snd speed1 +. b_val) ;; |
let passes_da_vinci (t : tree) : bool = let rec children childlist sum = match childlist with | [] -> sum | Branch (q, _) :: xs -> children (xs) (sum +. q *. q) | Leaf :: xs -> children (xs) (sum) in let compare prnt childs = (prnt *. prnt) >= children childs 0. in let rec siblings subtrees = match subtrees with | [] -... |
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) else au... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = match l with | [] -> [] | e :: els -> els in let l2 = match (List.rev l) with | [] -> [] | e :: els -> (List.rev els) in let l3 = List.combine l2 l1 in mode l3 ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit 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 ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_unit1 = fst(from_unit) in let time_unit1 = snd(from_unit) in let dist_unit2 = fst(to_unit) in let time_unit2 = snd(to_unit) in (to_unit, val_ *. (snd((convert_dist (dist_unit1, 1.) dist_unit2)) /. (snd(convert_time (time_unit... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let std_time = convert_time (time) (snd(speed_unit)) in let std_time_value = snd (std_time) in (fst(speed_unit), speed_val *. std_time_value) ;; let rec passes_da_vinci t = let rec sum_ l= match l with | [] -> 0. | Leaf :: tl -> sum... |
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) else ... |
let pair_mode (l: 'a list) : 'a * 'a = match l with |[] -> notimplemented() |[_]-> notimplemented() |x :: xs -> let l1 = xs in let l = List.rev l in let x::xs = l in let l2 = xs in let l2 = List.rev l2 in let tuple_l = List.combine l2 l1 in mode tuple_l ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit, val_) with | (Second,Hour,value) -> (Hour, value /. 3600.) | (Hour,Second,value) -> (Second, value *. 3600.) | (_, _, value) -> (from_unit, value) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit, val_) with | (Foot,Meter,value) -> (Meter, value *. 0.3048) | (Meter,Foot,value) -> (Foot, value /. 0.3048) | (Foot,Mile,value) -> (Mile, value /. 5280.0) | (Mile,Foot,value) -> (Foot, value *. 5280.0) | (Mile,... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_convert = convert_dist((fst from_unit),val_) (fst to_unit) in let time_convert = convert_time((snd from_unit),1.0) (snd to_unit) in (to_unit, snd dist_convert /. snd time_convert) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let temp = convert_speed a b_unit in (b_unit, snd temp +. b_val) ;; |
let passes_da_vinci t = let compute_sum (l : tree list) : float = let rec helper_sum (l : tree list) (acc : float): float = match l with | [] -> acc | x::xs -> match x with | Leaf -> helper_sum xs acc | Branch (width, _) -> helper_sum xs (acc +. (width ** 2.)) in helper_sum l 0. in let rec passes_da_vinci_helper (t : t... |
let mode (l: 'a list) : 'a = let l = List.sort compare l in let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | x::xs -> if x = cur_el then aux xs (x, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1)... |
let pair_mode (l: 'a list) : 'a * 'a = let reversedlist = List.rev l in match reversedlist with | [] -> failwith "Undefined input." | x::xs when xs = [] -> failwith "Undefined input." | x::xs -> let xs1 = List.rev xs in match l with | [] -> failwith "Undefined input." | x::xs2 -> mode (List.combine xs1 xs2) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second when from_unit <> to_unit -> (to_unit, val_ /. 3600.) | Hour when from_unit <> to_unit -> (to_unit, val_ *. 3600.) | _ -> (from_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot when from_unit <> to_unit -> if to_unit = Meter then (to_unit, val_ *. 0.3048) else (to_unit, val_ /. 5280.) | Meter when from_unit <> to_unit -> if to_unit = Foot then (to_unit, val_ /. 0.3048) else (to_unit,... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist_unit1, time_unit1) = from_unit in let (dist_unit2, time_unit2) = to_unit in let (a, b) = convert_dist (dist_unit1, val_) dist_unit2 in let (c, d) = convert_time (time_unit1, 1.) time_unit2 in (to_unit, b /. d) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (converted_speed_unit, converted_value) = convert_speed a b_unit in (b_unit, converted_value +. b_val) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | x::xs -> match x with | Leaf -> sum_ xs (acc +. 0.** 2.) | Branch(width, subtree) -> sum_ xs (acc +. width ** 2.) in let rec check l = match l with | [] -> true | Leaf::t1 -> check t1 | Branch(width, subtree)::t1 -> if width ** 2. >= sum_ subtree 0... |
let mode (l: 'a list) : 'a = let rec aux l ((c_el, c_num) : 'a * int) ((m_el, m_num) : 'a * int) = match List.sort compare l with | [] -> if c_num <= m_num then m_el else c_el | x :: xs -> if x = c_el then aux xs (c_el,(c_num+1)) (m_el,m_num) else if c_num > m_num then aux xs (x,1) (c_el, c_num) else aux xs (x,1) (m_el... |
let pair_mode (l: 'a list) : 'a * 'a = let rec rev l p= match l with | x :: y :: z -> rev (y::z) ((x,y)::p) | _ -> p in if List.length l >=2 then mode (rev l []) else failwith "Invalid inputs." ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit=Second && to_unit=Second then (to_unit,val_) else if from_unit=Hour && to_unit=Hour then (to_unit,val_) else if from_unit=Second && to_unit=Hour then (to_unit,val_ /. 3600.) else (to_unit,val_ *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit=to_unit then (to_unit,val_) else match from_unit with | Foot -> if to_unit=Meter then(to_unit,val_ *. 0.3048) else (to_unit,val_ /. 5280.) | Meter -> if to_unit=Foot then (to_unit,val_ /. 0.3048) else (to_unit,val_ /. 0.3048... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (to_unit,val_) else (to_unit,snd(convert_dist ((fst(from_unit)),val_) (fst(to_unit))) /. snd(convert_time (snd(from_unit),1.) (snd(to_unit)))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if fst(a) = b_unit then (b_unit,snd(a)+.b_val) else (b_unit,snd(convert_speed(fst(a),snd(a)) (b_unit)) +. b_val) ;; |
let passes_da_vinci t= let rec check l bool acc width= match l with | [] -> acc <= width **2. | Leaf::tl -> check tl bool acc width | Branch (width2, subtree)::tl -> let c = check subtree true 0.0 width2 in if c then check tl (bool && c) (acc +. width2 ** 2.) width else false in match t with | Leaf -> true | Branch(wid... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match List.sort compare 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,... |
let pair_mode (l: 'a list) : 'a * 'a = let rec helper l pairs= match l with | x :: y :: z -> helper (y::z) ((x,y)::pairs) | _ -> pairs in if List.length l < 2 then failwith "Invalid inputs." else mode (helper l []) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit=Second && to_unit=Second then (to_unit,val_) else if from_unit=Hour && to_unit=Hour then (to_unit,val_) else if from_unit=Second && to_unit=Hour then (to_unit,val_ /. 3600.) else (to_unit,val_ *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit=to_unit then (to_unit,val_) else match from_unit with | Foot -> if to_unit=Meter then(to_unit,val_ *. 0.3048) else (to_unit,val_ /. 5280.) | Meter -> if to_unit=Foot then (to_unit,val_ /. 0.3048) else (to_unit,val_ /. 0.3048... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (to_unit,val_) else (to_unit,snd(convert_dist ((fst(from_unit)),val_) (fst(to_unit))) /. snd(convert_time (snd(from_unit),1.) (snd(to_unit)))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if fst(a) = b_unit then (b_unit,snd(a)+.b_val) else (b_unit,snd(convert_speed(fst(a),snd(a)) (b_unit)) +. b_val) ;; |
let passes_da_vinci t= let rec check l bool acc width= match l with | [] -> acc <= width **2. | Leaf::tl -> check tl bool acc width | Branch (width2, subtree)::tl -> let c = check subtree true 0.0 width2 in if c then check tl (bool && c) (acc +. width2 ** 2.) width else false in match t with | Leaf -> true | Branch(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 compare cur_num max_num > 0 then cur_el else max_el | h :: t -> if compare h cur_el = 0 then aux t (cur_el, cur_num +1) (max_el, max_num) else if compare cur_num max_num > 0 then aux t (h, ... |
let pair_mode (l: 'a list) : 'a * 'a = if l = [] || List.length l < 2 then failwith "invalid list" else 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 to_unit with | Hour -> if fst(from_unit, val_) = to_unit then (from_unit, val_) else (to_unit, snd(from_unit, val_) /. 3600.) | Second -> if fst(from_unit, val_) = to_unit then (from_unit, val_) else (to_unit, snd(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 = to_unit then (from_unit, val_) else if from_unit = Mile then (to_unit, val_ *. 5280.) else (to_unit, val_ /. 0.3048) | Meter -> if from_unit = to_unit then (from_unit, val_) else if from_unit =... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if fst(from_unit, val_) = to_unit then (from_unit, val_) else match snd(to_unit) with | Hour -> if snd(from_unit) = snd(to_unit) then (to_unit, (snd(convert_dist (fst(from_unit), val_) (fst(to_unit))))) else (to_unit, (snd(convert_dis... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (fst(speed_unit), snd(convert_time (time) (snd(speed_unit))) *. speed_val) ;; let rec 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 +. (... |
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_... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "The list is empty" | [_] -> failwith "The list only has one element" | h :: t -> mode (convert_to_bigrams l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit = Hour then (to_unit, val_ /. 3600.) else (to_unit, val_) | Hour -> if to_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 from_unit with | Foot -> if to_unit = Mile then (to_unit, val_ /. 5280.) else if to_unit = Meter then (to_unit, val_ *. 0.3048) else (to_unit, val_) | Meter -> if to_unit = Mile then (to_unit, val_ /. 5280. /. 0.3048) else if to_un... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (to_unit, snd (convert_dist (fst from_unit, val_) (fst to_unit) ) /. snd (convert_time (snd from_unit, 1.) (snd to_unit))) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (fst speed_unit, speed_val *. snd (convert_time time (snd speed_unit))) ;; let sum_of_squares (t_list : tree list) : float = let rec aux (t_list: tree list) (cur_sum: float) = match t_list with | [] -> cur_sum | Leaf :: t -> aux t c... |
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_... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "The list is empty" | [_] -> failwith "The list only has one element" | h :: t -> mode (convert_to_bigrams l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then failwith "No negative values" else match from_unit with | Second -> if to_unit = Hour then (to_unit, val_ /. 3600.) else (to_unit, val_) | Hour -> if to_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 = if val_ < 0. then failwith "No negative values" else match from_unit with | Foot -> if to_unit = Mile then (to_unit, val_ /. 5280.) else if to_unit = Meter then (to_unit, val_ *. 0.3048) else (to_unit, val_) | Meter -> if to_unit = Mile ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then failwith "No negative values" else (to_unit, snd (convert_dist (fst from_unit, val_) (fst to_unit) ) /. snd (convert_time (snd from_unit, 1.) (snd to_unit))) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = if speed_val < 0. || snd time < 0. then failwith "No negative values" else (fst speed_unit, speed_val *. snd (convert_time time (snd speed_unit))) ;; let sum_of_squares (t_list : tree list) : float = let rec aux (t_list: tree list) ... |
let mode (l: 'a list) : 'a = match l with |[] -> failwith "Undefined input." | _ -> let l = List.rev (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 | x :: xs -> if cur_el = x then aux xs (cur_el, c... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Undefined input." else let copy1 = List.rev (List.tl (List.rev l)) in let copy2 = List.tl l in let tuples = List.combine copy1 copy2 in mode tuples ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (to_unit, val_ /. 3600.) | (Hour, Second) -> (to_unit, val_ *. 3600.) | (_, _) -> (to_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (to_unit, val_ *. 0.3048) | (Foot, Mile) -> (to_unit, val_ /. 5280.) | (Meter, Foot) -> (to_unit, val_ /. 0.3048) | (Meter, Mile) -> (to_unit, val_ /. 1609.344) | (Mile, Foot) -> (to_uni... |
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 res1 = snd (convert_dist (from_dist, val_) to_dist) in let res2 = snd (convert_time (to_time, res1) from_time) in (to_unit, res2) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_val = snd (convert_speed a b_unit) in (b_unit, a_val +. b_val) ;; |
let passes_da_vinci t: bool = let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> let sum_square = sum_children subtree 0. in let is_good_subtree = check subtree in if width ** 2. >= sum_square then is_good_subtree && 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) |h::t -> if h = cur_el then aux t (cur_el, cur_num + 1) (max_el, max_num) else(if cur_num > max_num then aux t (h, 1) (cur_el, cur_num) else(aux t ... |
let pair_mode (l: 'a list) : 'a * 'a = let rec makeTuples (prev : 'a) (l : 'a list) (tuples: ('a * 'a) list) = match l with | [] -> tuples | h::t -> let tuples = (prev, h)::tuples in makeTuples h t tuples in let tuplesList = makeTuples (List.hd l) (List.tl l) [] in if List.length tuplesList > 0 then mode tuplesList els... |
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 == Foot then (Foot, val_) else( if to_unit == Meter then (Meter, val_ *. 0.3048) else( (Mile, val_ /. 5280.) ) ) | Meter -> if to_unit == Foot then (Foot, val_ /. 0.3048) else( if to_unit == Mete... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (mDist, mTime) = from_unit in let (tDist, tTime) = to_unit in let _, nDistance = convert_dist (mDist, val_) tDist in let _, nTime = convert_time (mTime, 1.) tTime in (to_unit, nDistance/. nTime) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let tUnit, tVal = time in let sDistUnit, sTimeUnit = speed_unit in let _, mTval = convert_time(tUnit, tVal) sTimeUnit in (sDistUnit, mTval *. speed_val) ;; let rec passes_da_vinci t = let rec sumChildren trees (num: float) : float =... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with |[] -> if cur_num > max_num then cur_el else(max_el) |h::t -> if h = cur_el then aux t (cur_el, cur_num + 1) (max_el, max_num) else(if cur_num > max_num then aux t (h, 1) (cur_el, cur_num) else(aux t ... |
let pair_mode (l: 'a list) : 'a * 'a = let rec makeTuples (prev : 'a) (l : 'a list) (tuples: ('a * 'a) list) = match l with | [] -> tuples | h::t -> let tuples = (prev, h)::tuples in makeTuples h t tuples in let tuplesList = makeTuples (List.hd l) (List.tl l) [] in if List.length tuplesList > 0 then mode tuplesList els... |
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 == Foot then (Foot, val_) else( if to_unit == Meter then (Meter, val_ *. 0.3048) else( (Mile, val_ /. 5280.) ) ) | Meter -> if to_unit == Foot then (Foot, val_ /. 0.3048) else( if to_unit == Mete... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (mDist, mTime) = from_unit in let (tDist, tTime) = to_unit in let _, nDistance = convert_dist (mDist, val_) tDist in let _, nTime = convert_time (mTime, 1.) tTime in (to_unit, nDistance/. nTime) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let tUnit, tVal = time in let sDistUnit, sTimeUnit = speed_unit in let _, mTval = convert_time(tUnit, tVal) sTimeUnit in (sDistUnit, mTval *. speed_val) ;; let rec passes_da_vinci t = let rec sumChildren trees (num: float) : float =... |
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 | head :: rest -> if head = max_el then aux rest (cur_el, (cur_num+1) ) (max_el, (max_num+1) ) else if head = cur_el then if (cur_num = max_num) then aux rest (cur_el, (cur_num+1)) (cur... |
let pair_mode (l: 'a list) : 'a * 'a = let rec make_bigram_list (l: 'a list) : ('a * 'a) list = match l with | [] -> [] | _ :: [] -> [] | head :: rest -> (head, (List.hd rest)) :: make_bigram_list rest in mode (make_bigram_list l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) with | (Second, _) when to_unit = Hour -> (Hour, val_ /. 3600.) | (Hour, _) when to_unit = Second -> (Second, val_ *. 3600.) | (_, _) -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (Meter, val_ *. 0.3048 ) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Meter, Mile) -> (Mile, val_ /. 0.304... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match (from_unit, to_unit) with | ((x, Second), (y, Hour)) -> let (_, val_con)= convert_dist (x, val_) y in (to_unit, val_con *. 3600.) | ((x, Hour), (y, Second)) -> let (_, val_con)= convert_dist (x, val_) y in (to_unit, val_con /. 3... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_d_unit, speed_t_unit) = speed_unit in let (_, time_conv_val) = convert_time time speed_t_unit in (speed_d_unit, speed_val *. time_conv_val) ;; let rec passes_da_vinci t = let rec sum_of_squares (subtrees : tree list) (cum... |
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 | head :: rest -> if head = max_el then aux rest (cur_el, (cur_num+1) ) (max_el, (max_num+1) ) else if head = cur_el then if (cur_num = max_num) then aux rest (cur_el, (cur_num+1)) (cur... |
let pair_mode (l: 'a list) : 'a * 'a = let rec make_bigram_list (l: 'a list) : ('a * 'a) list = match l with | [] -> [] | _ :: [] -> [] | head :: rest -> (head, (List.hd rest)) :: make_bigram_list rest in if List.length l <2 then failwith "List must be have at least 1 pair of elements" else mode (make_bigram_list l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (Hour, val_ /. 3600.) | (Hour, Second) -> (Second, val_ *. 3600.) | (_, _) -> (to_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (Meter, val_ *. 0.3048 ) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Meter, Mile) -> (Mile, val_ /. 0.304... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (_, val_dist) = convert_dist ((fst from_unit), val_) (fst to_unit) in let (_, val_time) = convert_time ((snd from_unit), 1.) (snd to_unit) in (to_unit, (val_dist /. val_time)) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_d_unit, speed_t_unit) = speed_unit in let (_, time_val) = convert_time time speed_t_unit in (speed_d_unit, speed_val *. time_val) ;; let rec passes_da_vinci t = let rec sum_of_squares (subtrees : tree list) (cumul : float... |
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 compare x cur_el = 0 && (cur_num+1)>max_num then aux xs (x,(cur_num+1)) (x,(cur_num+1)) else if compare x cur_el = 0 then aux xs (x,(cur_num+1)) (max_el,max_num) else aux xs... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = l in let l2 = l in let l1 = removeHead l1 in let l2 = List.rev l2 in let l2 = removeHead l2 in let l2 = List.rev l2 in let l3 = List.combine l2 l1 in mode l3 ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with |Hour -> if to_unit = Second then (Second, val_ *. 3600.) else (Hour, val_) |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 = 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 = Mile then (Mile, (val_ /. 0.3048)/.5280.) else if to_unit = Foot the... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (todistance, totime) = (to_unit) in let (fromdistance, fromtime) = (from_unit) in let (todistance_two, val_two) = convert_dist(fromdistance, val_) todistance in let (totime_two, div) = convert_time(fromtime, 1.) totime in (to_unit... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (speed, val_) = a in let (a_unit, a_val) = convert_speed (speed, val_) b_unit in (b_unit, a_val+.b_val) ;; |
let passes_da_vinci t = let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not(check subtree) || (sum_ subtree 0. > (width*.width)) then false else check tl in check [t] ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.