text stringlengths 0 601k |
|---|
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... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Invalid input." | hd::tl -> 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 -> (if to_unit = Second then (to_unit, val_) else (to_unit, val_/.3600.)) | Hour -> (if to_unit = Hour then (to_unit, val_) else (to_unit, val_*.3600.)) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> (if to_unit = Foot then (to_unit, val_) else if to_unit = Meter then (to_unit, val_*.0.3048) else (to_unit, val_/.5280.)) | Meter -> (if to_unit = Meter then (to_unit, val_) else if to_unit = Foot then (to_... |
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), 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, b_val +. snd(convert_speed(fst(a), snd(a)) b_unit)) ;; |
let passes_da_vinci t = match t with | Leaf -> true | Branch(width, subtree) -> (width *. width >= (add_square_width subtree) && check subtree) ;; |
let mode (l: 'a list) : 'a = let rec aux lst (cur_elem, cur_count) (mode_elem, mode_count) index = if index = List.length lst then mode_elem else if List.nth lst index = cur_elem then if succ cur_count > mode_count then aux lst (cur_elem, succ cur_count) (cur_elem, succ cur_count) (succ index) else aux lst (cur_elem, s... |
let pair_mode (l : 'a list) : 'a * 'a = let rec aux lst newlst ix1 ix2 = if ix2 = List.length lst then newlst else aux lst ((List.nth lst ix1, List.nth lst ix2) :: newlst) (succ ix1) (succ ix2) in mode (aux l [] 0 1) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit = to_unit then to_unit, val_ else ( let second_to_hour s = Hour, s /. 3600. in let hour_to_second h = Second, h *. 3600. in match from_unit with | Second -> second_to_hour val_ | Hour -> hour_to_second val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit = to_unit then to_unit, val_ else ( let foot_to_meter foot : dist_unit value = Meter, foot *. 0.3048 in let foot_to_mile foot : dist_unit value = Mile, foot /. 5280. in let meter_to_foot meter : dist_unit value = Foot, meter... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let value_to_elem = function | _, x -> x in let d_from, t_from = from_unit in let d_to, t_to = to_unit in ( (d_to, t_to) , value_to_elem (convert_dist (d_from, value_to_elem (convert_time (t_to, val_) t_from)) d_to) ) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let t_unit, t_val = time in let d_unit, st_unit = speed_unit in let _, tv = (convert_time (t_unit, t_val) st_unit) in d_unit, tv *. speed_val ;; let square x = x *. x let rec aux tlist sum outerlst = match tlist with | [] -> (match ... |
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 l (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux l (x, 1) (cur_el, cur_num) else aux l ... |
let pair_mode (l: 'a list) : 'a * 'a = notimplemented () ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit = Second then (from_unit, val_) else (Hour, val_ /. 3600.) | Hour -> if to_unit = Hour then (from_unit, val_) else (Second, val_ *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> if to_unit = Foot then (from_unit, val_) else if to_unit = Meter then (Meter, val_ *. 0.3048) else (Mile, val_ /. 5280.) | Meter -> if to_unit = Meter then (from_unit, val_) else if to_unit = Foot then (Foo... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match fst(from_unit) with | Foot -> ( match snd(from_unit) with | Hour -> ( match fst(to_unit) with | Foot -> ( match snd(to_unit) with | Hour -> ((Foot, Hour), val_) | Second -> ((Foot, Second), snd(convert_time (Hour, val_) Second))... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = notimplemented () ;; let rec passes_da_vinci t = notimplemented () ;; |
let mode (l: 'a list) : 'a = match l with | [] -> failwith "empty list" | _ -> 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 | c :: sl -> if (compare c cur_el) = 0 then aux sl (cur_el, (cur_num + 1)) (max_el, max_num) else... |
let pair_mode (l: 'a list) = if (List.length l) = 0 || (List.length l) = 0 then failwith "list too small" else let rec pairList l1 l2 lpairs = match l2 with | [] -> lpairs | l2c :: sl2 -> match l1 with | [] -> failwith "list improperly sent" | l1c :: sl1 -> pairList sl1 sl2 ((l1c, l2c) :: lpairs) in let lpairs = pairLi... |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then failwith "negative time" else match from_unit with | Second -> (match to_unit with | Second -> (to_unit, val_) | Hour -> (to_unit, (val_ /. 3600.))) | Hour -> (match to_unit with | Second -> (to_unit, (val_ *. 3600.)) |... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if val_ < 0. then failwith "negative distance" else match from_unit with | Foot -> ( match to_unit with | Foot -> (to_unit, val_) | Meter -> (to_unit, val_ *. 0.3048) | Mile -> (to_unit, val_ /. 5280.)) | Meter -> ( match to_unit with | ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then failwith "negative speed" else let (from_dist, from_time) = from_unit in let (to_dist, to_time) = to_unit in let (_, fd) = convert_dist (from_dist, val_) to_dist in let (_, ft) = convert_time (from_time, 1.) to_time ... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if (snd a < 0.) || b_val < 0. then failwith "negative speed" else let (_, ac_val) = convert_speed a b_unit in (b_unit, (ac_val +. b_val)) ;; |
let passes_da_vinci t = let rec sum_squares (l : tree list) (sum: float) : float = match l with | [] -> sum | b :: sl -> match b with | Leaf -> sum_squares sl sum | Branch (w, _) -> sum_squares sl (sum +. (w ** 2.)) in let is_true (t: tree): bool = match t with | Leaf -> true | Branch (w, tl) -> ((compare (w ** 2.) (su... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = function | [] -> if cur_num > max_num then cur_el else max_el | hd::tl -> if cur_el = hd then aux l (cur_el, (cur_num + 1)) (max_el, max_num) tl else if cur_num > max_num then aux l ( hd, 1) (cur_el, cur_num) tl e... |
let pair_mode (l: 'a list) : 'a * 'a = let m1 = List.tl(l) in let m2 = List.rev (List.tl (List.rev l)) in let p = List.combine m2 m1 in mode p ;; |
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 from_unit with | Second -> (to_unit, val_ /. 3600.) | Hour -> (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 -> (match to_unit with | Foot -> (to_unit, val_) | Meter -> (to_unit, val_ *. 0.3048 ) | Mile -> (to_unit, val_ /. 5280.)) | Meter -> (match to_unit with | Foot... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let term1 = fst from_unit in let term2 = snd from_unit in let c1 = convert_dist (term1, val_) (fst(to_unit)) in let c2 = convert_time (term2, val_) (snd(to_unit)) in ((fst to_unit, snd to_unit), val_ *. (snd(c1) /. snd(c2))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let c = convert_speed ((fst a), snd a) b_unit in (b_unit, b_val +. (snd c));; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] | [Leaf] -> 0. | Leaf :: tl -> sum_ tl acc | [Branch (width, subtree)] -> (acc +. (width ** 2.)) | Branch (width, subtree) :: tl -> sum_ tl (acc +. (width ** 2.)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtr... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = function | [] -> if cur_num > max_num then cur_el else max_el | hd::tl -> if cur_el = hd then aux l (cur_el, (cur_num + 1)) (max_el, max_num) tl else if cur_num > max_num then aux l ( hd, 1) (cur_el, cur_num) tl e... |
let pair_mode (l: 'a list) : 'a * 'a = let m1 = List.tl(l) in let m2 = List.rev (List.tl (List.rev l)) in let p = List.combine m2 m1 in mode p ;; |
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 from_unit with | Second -> (to_unit, val_ /. 3600.) | Hour -> (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 -> (match to_unit with | Foot -> (to_unit, val_) | Meter -> (to_unit, val_ *. 0.3048 ) | Mile -> (to_unit, val_ /. 5280.)) | Meter -> (match to_unit with | Foot... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let term1 = fst from_unit in let term2 = snd from_unit in let c1 = convert_dist (term1, val_) (fst(to_unit)) in let c2 = convert_time (term2, val_) (snd(to_unit)) in ((fst to_unit, snd to_unit), val_ *. (snd(c1) /. snd(c2))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let c = convert_speed ((fst a), snd a) b_unit in (b_unit, b_val +. (snd c));; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] | [Leaf] -> 0. | Leaf :: tl -> sum_ tl acc | [Branch (width, subtree)] -> (acc +. (width ** 2.)) | Branch (width, subtree) :: tl -> sum_ tl (acc +. (width ** 2.)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtr... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = function | [] -> if cur_num > max_num then cur_el else max_el | hd::tl -> if cur_el = hd then aux l (cur_el, (cur_num + 1)) (max_el, max_num) tl else if cur_num > max_num then aux l ( hd, 1) (cur_el, cur_num) tl e... |
let pair_mode (l: 'a list) : 'a * 'a = let m1 = List.tl(l) in let m2 = List.rev (List.tl (List.rev l)) in let p = List.combine m2 m1 in mode p ;; |
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 from_unit with | Second -> (to_unit, val_ /. 3600.) | Hour -> (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 -> (match to_unit with | Foot -> (to_unit, val_) | Meter -> (to_unit, val_ *. 0.3048 ) | Mile -> (to_unit, val_ /. 5280.)) | Meter -> (match to_unit with | Foot... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let term1 = fst from_unit in let term2 = snd from_unit in let c1 = convert_dist (term1, val_) (fst(to_unit)) in let c2 = convert_time (term2, val_) (snd(to_unit)) in ((fst to_unit, snd to_unit), val_ *. (snd(c1) /. snd(c2))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let c = convert_speed ((fst a), snd a) b_unit in (b_unit, b_val +. (snd c));; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] | [Leaf] -> acc | Leaf :: tl -> sum_ tl acc | [Branch (width, subtree)] -> (acc +. (width ** 2.)) | Branch (width, subtree) :: tl -> sum_ tl (acc +. (width ** 2.)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subt... |
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 | e :: es -> if cur_el = e then if (succ cur_num > max_num) then aux es (e, succ cur_num) (e, succ cur_num) else aux es (e, succ cur_num) (max_el, max_num) else aux es (e, 1) (max_el, m... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] | _ :: [] -> failwith "Input list is too small" | _ -> mode (List.combine (List.rev (let _ :: l2 = List.rev l in l2)) (let _ :: l1 = l in l1)) ;; |
let convert_time ((from_unit, val_) : time_unit value) (to_unit : time_unit) : time_unit value = match (from_unit, val_) with | (Second, a) -> if to_unit = Second then (Second, a) else(Hour, a /. 3600.) | (Hour, a) -> if to_unit = Hour then (Hour, a) else(Second, a *. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) (to_unit : dist_unit) : dist_unit value = match (from_unit, val_) with | (Foot, a) -> if to_unit = Foot then (Foot, a) else(if to_unit = Mile then (Mile, a /. 5280.) else (Meter, a *. 0.3048)) | (Meter, a) -> if to_unit = Meter then (Meter, a) else(if to_unit = Mil... |
let convert_speed ((from_unit, val_) : speed_unit value) (to_unit: speed_unit) : speed_unit value = let (((dist1,time1),a),(dist2,time2)) = ((from_unit, val_), to_unit) in if (dist1, time1) = (dist2, time2) then ((dist2, time2), a) else(if dist2 = dist1 then ((dist2, time2), a /. snd (convert_time (time1, 1.) time2)) e... |
let dist_traveled (time : time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let ((dur,a),(d,_)) = (time, speed_unit) in (d, (snd (convert_speed (speed_unit, speed_val) (d, dur)) *. a)) ;; let rec sum_square (t: tree list) : float = match t with | [] -> 0. | Leaf :: branches -> 0. | branc... |
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) els... |
let pair_mode (l: 'a list) : 'a * 'a = let rec create_tpl_l lst acc = if ((List.length lst) < 2) then acc else let tpl = (List.nth lst 0, List.nth lst 1) in create_tpl_l (List.tl lst) (tpl :: acc) in if (List.length l) < 2 then failwith "list must be >1 in length" else let tpl_l = create_tpl_l l [] in mode tpl_l ;; |
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 from_unit with | Second -> (Hour, val_ /. 3600.) | Hour -> (Second, 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 match from_unit with | Foot -> if to_unit = Meter then (Meter, val_ *. 0.3048) else (Mile, val_ /. 5280.) | Meter -> if to_unit = Foot then (Foot, val_ /. 0.3048) else (Mile, (val_ /. 0.... |
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, from_time) = from_unit in let (to_dist, to_time) = to_unit in let inv (fl: float) = 1. /. fl in let (_, dist) = convert_dist (from_dist, val_) to_dist in let (_, inv_s... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_dist, speed_time) = speed_unit in let (_, time_val) = convert_time time speed_time in (speed_dist, (speed_val *. time_val)) ;; let rec passes_da_vinci t = let rec sum_of_sqr (tree_l: tree list) (acc: float) = match tree_l... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if (cur_num < max_num) || (cur_num = max_num && cur_el >= max_el) then max_el else cur_el | el :: l_tl -> if el = cur_el then aux l_tl (cur_el, cur_num+1) (max_el, max_num) else ( if (cur_num ... |
let pair_mode (l: 'a list) : 'a * 'a = let rec create_tpl_l lst acc = if ((List.length lst) < 2) then acc else let tpl = (List.nth lst 0, List.nth lst 1) in create_tpl_l (List.tl lst) (tpl :: acc) in if (List.length l) < 2 then failwith "list must be >1 in length" else let tpl_l = create_tpl_l l [] in mode tpl_l ;; |
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 from_unit with | Second -> (Hour, val_ /. 3600.) | Hour -> (Second, 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 match from_unit with | Foot -> if to_unit = Meter then (Meter, val_ *. 0.3048) else (Mile, val_ /. 5280.) | Meter -> if to_unit = Foot then (Foot, val_ /. 0.3048) else (Mile, (val_ /. 0.... |
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, from_time) = from_unit in let (to_dist, to_time) = to_unit in let inv (fl: float) = 1. /. fl in let (_, dist) = convert_dist (from_dist, val_) to_dist in let (_, inv_s... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_dist, speed_time) = speed_unit in let (_, time_val) = convert_time time speed_time in (speed_dist, (speed_val *. time_val)) ;; let rec passes_da_vinci t = let rec sum_of_sqr (tree_l: tree list) (acc: float) = match tree_l... |
let mode (l: 'a list) : 'a = let rec aux (l: 'a list) ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) : 'a = match l with | [] -> 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 aux xs (x, 1) (max_el,... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then invalid_arg "list must have at least 2 elements" else let la = List.rev (List.tl (List.rev l)) in let lb: 'b list = List.combine la (List.tl l) in let f e = Some e in let lc = List.map f lb in match mode lc with | None -> failwith "this shouldn't happen, ... |
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 from_unit with | Hour -> (Second, val_ *. 3600.) | Second -> (Hour, val_ /. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (Meter, val_ *. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mile) -> (Mile, val_ /. 0.3048 /. 5280.) | (Mile, Foot) -> (Foot, val_... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let get_dist_unit (a, _) = a in let get_time_unit (_, b) = b in let (_, t) = convert_time (get_time_unit from_unit, 1.) (get_time_unit to_unit) in let (_, d) = convert_dist (get_dist_unit from_unit, val_ /. t) (get_dist_unit to_unit) ... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let get_dist_unit (a, _) = a in let get_time_unit (_, b) = b in let (_, t) = convert_time time (get_time_unit speed_unit) in (get_dist_unit speed_unit, speed_val *. t) ;; let rec passes_da_vinci t = let sq (t : tree) : float = match... |
let test1 = [3; 4; 1; 2; 5; 3; 4; 3; 1; 2] let rec number_of_occurences (l: 'a list) (num: 'a): int = match l with | [] -> 0 | x :: xs -> if x = num then 1 + number_of_occurences xs num else number_of_occurences xs num let rec find_max (full_list: 'a list) (iterated_list: 'a list) (max_num: int) (max_occ: 'a) = match i... |
let mode (arr: 'a list) : 'a = match arr with | [] -> failwith "Undefined input." | x :: xs -> let max_occ = (number_of_occurences arr x) in find_max (List.sort compare arr) (List.sort compare xs) max_occ x ;; let rec create_pairs (og_l: 'a list) (built_l: ('a * 'a) list): ('a * 'a) list = match og_l with | [] -> built... |
let pair_mode (l: 'a list) : 'a * 'a = let arr_of_pairs = create_pairs l [] in mode (List.sort compare (List.rev (create_pairs l []))) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) with | (Second, _) -> if to_unit = Hour then (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, val_) with | (Foot, _) -> if to_unit = Meter then (to_unit, val_*.0.3048) else if to_unit = Mile then (to_unit, val_/.5280.) else (to_unit, val_) | (Meter, _) -> if to_unit = Foot then (to_unit, val_/.0.3048) else if to... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_distance_unit, from_time_unit) = from_unit in let (to_distance_unit, to_time_unit) = to_unit in let (_, distance) = convert_dist (from_distance_unit, val_) to_distance_unit in let (_, time) = convert_time (from_time_unit, 1.... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (asked_time_unit, asked_time_value) = time in let (actual_distance_unit, actual_time_unit) = speed_unit in let (_, converted_time_value) = convert_time time actual_time_unit in (actual_distance_unit, (converted_time_value)*.spee... |
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, cur_num) else (max_el, max_num) | (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... |
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (l: 'a list) (tar :('a * 'a) list) (pre : 'a) = match l with | [] -> tar | (h :: t) -> aux t ((pre, h) :: tar) h in let newlist: ('a * 'a) list = [] in match l with | [] -> failwith "Invalid input. The list is empty!" | [x] -> failwith "Invalid input. The list only has... |
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.0)) | Hour -> (match to_unit with | Second -> (Second, (val_ *. 3600.0)) | 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.0)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048 ) | Meter -> (Meter, val_) | Mi... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d, t) : (float * float) = (snd (convert_dist (fst from_unit, val_) Meter), snd (convert_time (snd from_unit, 1.0) Second)) in let dd = d /. t in match to_unit with | (Foot, Second) -> ((Foot, Second), dd /. 0.3048) | (Foot, Hour)... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let sa = (snd (convert_speed a (fst b_unit, snd b_unit))) in (b_unit, sa +. 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 *. width in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not ((check subtree) && ((sum_ subtree 0.0) <= ... |
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, cur_num) else (max_el, max_num) | (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... |
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (l: 'a list) (tar :('a * 'a) list) (pre : 'a) = match l with | [] -> tar | (h :: t) -> aux t ((pre, h) :: tar) h in let newlist: ('a * 'a) list = [] in match l with | [] -> failwith "Invalid input. The list is empty!" | [x] -> failwith "Invalid input. The list only has... |
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.0)) | Hour -> (match to_unit with | Second -> (Second, (val_ *. 3600.0)) | 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.0)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048 ) | Meter -> (Meter, val_) | Mi... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d, t) : (float * float) = (snd (convert_dist (fst from_unit, val_) Meter), snd (convert_time (snd from_unit, 1.0) Second)) in let dd = d /. t in match to_unit with | (Foot, Second) -> ((Foot, Second), dd /. 0.3048) | (Foot, Hour)... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let sa = (snd (convert_speed a (fst b_unit, snd b_unit))) in (b_unit, sa +. 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 *. width in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not ((check subtree) && ((sum_ subtree 0.0) <= ... |
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, cur_num) else (max_el, max_num) | (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... |
let pair_mode (l: 'a list) : 'a * 'a = let rec aux (l: 'a list) (tar :('a * 'a) list) (pre : 'a) = match l with | [] -> tar | (h :: t) -> aux t ((pre, h) :: tar) h in let newlist: ('a * 'a) list = [] in match l with | [] -> failwith "Invalid input. The list is empty!" | [x] -> failwith "Invalid input. The list only has... |
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.0)) | Hour -> (match to_unit with | Second -> (Second, (val_ *. 3600.0)) | 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.0)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048 ) | Meter -> (Meter, val_) | Mi... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d, t) : (float * float) = (snd (convert_dist (fst from_unit, val_) Meter), snd (convert_time (snd from_unit, 1.0) Second)) in let dd = d /. t in match to_unit with | (Foot, Second) -> ((Foot, Second), dd /. 0.3048) | (Foot, Hour)... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let sa = (snd (convert_speed a (fst b_unit, snd b_unit))) in (b_unit, sa +. 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 *. width) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not ((check subtree) && ((sum_ subtree 0.0) <... |
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, cur_num) else (max_el, max_num) | (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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.