text stringlengths 0 601k |
|---|
let mode (l: 'a list) : 'a = let m = List.sort compare l in let rec aux m ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match m with | [] -> if cur_num > max_num then cur_el else max_el |x::rest -> if cur_el = x then aux rest (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux res... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = List.tl l and l2 = List.rev (List.tl (List.rev l)) in let toenter = List.combine l2 l1 in mode toenter ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if not (val_ >= 0.) then failwith ("wrong input") else match from_unit with | Second -> if to_unit = Hour then ( Hour, val_/.3600.) else (from_unit, val_) | Hour -> if to_unit = Second then ( Second, val_*.3600.) else (from_unit, val_) ;... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if not (val_ >= 0.) then failwith ("wrong input") else match from_unit with | Foot -> if to_unit = Meter then ( Meter, val_*.0.3048) else if to_unit = Mile then (Mile, val_/.5280.) else (from_unit, val_) | Meter -> if to_unit = Foot then... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if not (val_ >= 0.) then failwith ("wrong input") else let from_unit_dist = fst(from_unit) and from_unit_time = snd(from_unit) and to_unit_dist = fst(to_unit) and to_unit_time = snd(to_unit) in let next_value = snd(convert_dist (from_... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let converted = convert_speed (fst (a) , snd(a)) b_unit in let added = snd(converted) +. b_val in (b_unit, added) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch (w, _) :: tl -> sum_ tl (acc +. w *. w) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (w, trees) :: tl -> if sum_ trees 0. <= w *. w && check trees then check tl else false in ch... |
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 | x :: remainder -> if cur_el = x then aux remainder (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux remainder (x, 1) (cur_el, cur_num) else aux remainder (x, 1) (max_el,max... |
let pair_mode (l: 'a list) : 'a * 'a = let rec my_pair (l: 'a list):('a*'a) list = match l with | [] -> [] |[pp1;pp2] -> [(pp1,pp2)] |[_] -> [] |pp1::pp2::tail -> (pp1,pp2)::(my_pair(pp2::tail)) in let l = l in mode (my_pair l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if to_unit = Hour && from_unit = Second then (from_unit,val_ /. 3600.) else if to_unit = Second && from_unit = Hour then (from_unit,val_ *. 3600.) else from_unit, val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if to_unit = Meter && from_unit = Foot then (from_unit,val_ *. 0.3048) else if to_unit = Foot && from_unit = Meter then (from_unit,val_ /. 0.3048) else if to_unit = Mile && from_unit = Meter then (from_unit,val_ /. 1609.344) else if to_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (_,from_time) = from_unit in let (from_dist,_) = from_unit in let (_,to_time) = to_unit in let (to_dist,_) = to_unit in let (new_time, time) = convert_time (from_time, 1.) to_time in let (new_dist, dist) = convert_dist ((from_dist... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (time_x, time) = time in let (speed_distance, _) = speed_unit in let ((final_dist, _), last_val) = convert_speed (speed_unit, speed_val) (speed_distance, time_x) in (final_dist, last_val *. time) ;; let treeA = Branch (5., [ Bra... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = notimplemented () in notimplemented () ;; |
let pair_mode (l: 'a list) : 'a * 'a = notimplemented () ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if to_unit = Hour && from_unit = Second then (from_unit,val_ /. 3600.) else if to_unit = Second && from_unit = Hour then (from_unit,val_ *. 3600.) else from_unit, val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if to_unit = Meter && from_unit = Foot then (from_unit,val_ *. 0.3048) else if to_unit = Foot && from_unit = Meter then (from_unit,val_ /. 0.3048) else if to_unit = Mile && from_unit = Meter then (from_unit,val_ /. 1609.344) else if to_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = (Meter, Second) && to_unit = (Meter, Hour) then (from_unit, val_ *. 3600.) else if from_unit = (Meter, Second) && to_unit = (Foot, Second) then (from_unit, val_ /. 0.3048) else if from_unit = (Meter, Second) && to_unit ... |
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 = let sorted_list = List.sort compare l in match l with | [] -> failwith "List too small." | _ -> 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 (if cur_el < max_el then cur_el else max_el) else (if cur_num < max_nu... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "List is too small." else (let x = (List.tl l)@[(List.hd l)] in mode (List.tl(List.rev(List.combine l x)))) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if fst(from_unit, val_) = Second then (if to_unit = Hour then (Hour, (val_ /. 3600.0)) else (Second, val_)) else (if to_unit = Second then (Second, (val_ *. 3600.0)) else (Hour, val_)) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let unit1 = fst(from_unit, val_) in match unit1 with | Foot -> if to_unit = Foot then (Foot, val_) else (if to_unit = Meter then (Meter, (val_ *. 0.3048)) else (Mile, (val_ /. 5280.0))) | Meter -> if to_unit = Meter then (Meter, val_) el... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let unit1 = fst(from_unit) in let unit2 = fst(to_unit) in let time1 = snd(from_unit) in let time2 = snd(to_unit) in ((unit2, time2), (snd(convert_dist (unit1, val_) unit2) /. snd(convert_time (time1, 1.0) time2))) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = if snd(speed_unit) = fst(time) then ((fst(speed_unit)), (speed_val *. snd(time))) else ((fst(speed_unit)), (speed_val *. (snd(convert_time ((fst(time)), (snd(time))) (snd(speed_unit)))))) ;; let rec sum l (acc: float) = match l 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 |hd::tl -> let cur_num = if hd = cur_el then cur_num + 1 else cur_num in match tl with |[] -> if cur_num > max_num then cur_el else max_el |hd2::tl2... |
let pair_mode (l: 'a list) : 'a * 'a = match List.length l with |0 -> failwith "invalid input: the length is 0" |1 -> failwith "invalid input: the length is 1" |_ -> let l1 = l in let l2 = l in let rev_l2 = List.rev l2 in match l1 with |[] -> failwith "invalid input" |hd1::tl1 -> let l1_removed = tl1 in match rev_l2 wi... |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let given_time_unit = fst(from_unit, val_) in let given_value = snd(from_unit, val_) in if given_value < 0. then failwith "invalid input" else if given_time_unit = to_unit then (given_time_unit, given_value) else if given_time_unit = Sec... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let given_dist_unit:dist_unit = fst(from_unit, val_) in let given_value = snd(from_unit, val_) in match (given_value < 0.) with | true -> failwith "invalid input" | _ -> if given_dist_unit = to_unit then (given_dist_unit, given_value) el... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then failwith "invalid input" else let given_dist_unit = fst(fst(from_unit, val_)) in let given_time_unit = snd(fst(from_unit, val_)) in let to_dist_unit = fst(to_unit) in let to_time_unit = snd(to_unit) in let dist_to_mu... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let value_a = snd a in let value_b = snd(b_unit, b_val) in if value_a < 0. || value_b < 0. then failwith "invalid input" else let common_speed_unit = fst(b_unit, b_val) in let converted_speed = convert_speed a common_speed_un... |
let passes_da_vinci t = let rec sum_ l acc= match l with |[] -> acc |Leaf :: t1 -> sum_(t1)(acc +. 0.0) |Branch (width, subtree) :: t1 -> let squared_width = width ** 2. in sum_(t1)(acc+.squared_width) in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> let squared_bra... |
let mode (l: 'a list) : 'a = match l with | [] -> failwith "Undefined input" | _ -> let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | x :: xs -> if cur_el = x && cur_num > max_num then aux xs (cur_el, cur_num + 1) (cur_el, cur_num) else if cur_el = x then aux xs... |
let pair_mode (l: 'a list) : 'a * 'a = match l with |[]-> failwith "Undefined input - empty list" |[_]-> failwith "Undefined input - only one element in list" |_ -> let list_first_removed = List.tl l in let list_reversed = List.rev l in let list_first_removed_rev = List.tl list_reversed in let list_last_removed = List.... |
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 |Meter -> if to_unit = Foot then (Foot, val_ /. 0.3048) else if to_unit = Mile then (Mile, (val_ /. 0.3048) /. 5280. ) else (Meter, val_) |Mile -> if to_unit = Foot then (Foot, val_ *. 5280.) else if to_unit = Meter ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distance_initial = fst from_unit in let time_initial = snd from_unit in let distance_final = fst to_unit in let time_final = snd to_unit in let distance_converted = snd (convert_dist (distance_initial, val_) distance_final) in let... |
let add_speed ((a_unit, a_val) : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_converted = snd (convert_speed (a_unit, a_val) (b_unit)) in let added_speed = a_converted +. b_val in ((b_unit), added_speed);; |
let passes_da_vinci t = match t with |Leaf -> true |_ -> (passes_da_vinci_two 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 | [] -> max_el | hd :: tl -> let cur_el, cur_num = if hd = cur_el then cur_el, cur_num + 1 else hd, 1 in aux tl (cur_el, cur_num) (if cur_num > max_num then cur_el, cur_num else max_el, max_num) in ma... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] | [_] -> raise (Invalid_argument "list needs to contain at least two elements") | l -> mode (List.combine (l |> List.rev |> List.tl |> List.rev) (List.tl l)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let scalar = match from_unit, to_unit with | Hour, Second -> 3600. | Second, Hour -> 1. /. 3600. | Hour, Hour | Second, Second -> 1. in to_unit, val_ *. scalar ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let rec scalar from_unit to_unit = match from_unit, to_unit with | Mile, Foot -> 5280. | Foot, Meter -> 0.3048 | Mile, Meter -> (scalar Mile Foot) *. (scalar Foot Meter) | Foot, Mile | Meter, Foot | Meter, Mile -> 1. /. (scalar to_unit f... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let _, dist_scalar = convert_dist ((fst from_unit), 1.) (fst to_unit) in let _, time_scalar = convert_time ((snd from_unit), 1.) (snd to_unit) in to_unit, val_ *. dist_scalar /. time_scalar ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let _, time = convert_time time (snd speed_unit) in fst speed_unit, speed_val *. time ;; let rec passes_da_vinci t = let sum_of_squares ts = ts |> List.rev_map (fun t -> match t with | Branch(w, _) -> w | Leaf -> 0.) |> List.rev_map... |
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 -> let cur_el, cur_num = if hd = cur_el then cur_el, cur_num + 1 else hd, 1 in aux tl (cur_el, cur_num) (if cur_num > max_num then cur_el, cur_num else max_el, max_num) in ma... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] | [_] -> raise (failwith "list needs to contain at least two elements") | l -> mode (List.combine (l |> List.rev |> List.tl |> List.rev) (List.tl l)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let scalar = match from_unit, to_unit with | Hour, Second -> 3600. | Second, Hour -> 1. /. 3600. | Hour, Hour | Second, Second -> 1. in to_unit, val_ *. scalar ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let rec scalar from_unit to_unit = match from_unit, to_unit with | Mile, Foot -> 5280. | Foot, Meter -> 0.3048 | Mile, Meter -> (scalar Mile Foot) *. (scalar Foot Meter) | Foot, Mile | Meter, Foot | Meter, Mile -> 1. /. (scalar to_unit f... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let _, dist_scalar = convert_dist ((fst from_unit), 1.) (fst to_unit) in let _, time_scalar = convert_time ((snd from_unit), 1.) (snd to_unit) in to_unit, val_ *. dist_scalar /. time_scalar ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let _, time = convert_time time (snd speed_unit) in fst speed_unit, speed_val *. time ;; let rec passes_da_vinci t = let sum_of_squares ts = ts |> List.rev_map (fun t -> match t with | Branch(w, _) -> w | Leaf -> 0.) |> List.rev_map... |
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 -> let cur_el, cur_num = if hd = cur_el then cur_el, cur_num + 1 else hd, 1 in aux tl (cur_el, cur_num) (if cur_num > max_num then cur_el, cur_num else max_el, max_num) in ma... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] | [_] -> raise (failwith "list needs to contain at least two elements") | l -> mode (List.combine (l |> List.rev |> List.tl |> List.rev) (List.tl l)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let scalar = match from_unit, to_unit with | Hour, Second -> 3600. | Second, Hour -> 1. /. 3600. | Hour, Hour | Second, Second -> 1. in to_unit, val_ *. scalar ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let rec scalar from_unit to_unit = match from_unit, to_unit with | Mile, Foot -> 5280. | Foot, Meter -> 0.3048 | Mile, Meter -> (scalar Mile Foot) *. (scalar Foot Meter) | Foot, Mile | Meter, Foot | Meter, Mile -> 1. /. (scalar to_unit f... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let _, dist_scalar = convert_dist ((fst from_unit), 1.) (fst to_unit) in let _, time_scalar = convert_time ((snd from_unit), 1.) (snd to_unit) in to_unit, val_ *. dist_scalar /. time_scalar ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let _, time = convert_time time (snd speed_unit) in fst speed_unit, speed_val *. time ;; let rec passes_da_vinci t = let sum_of_squares ts = ts |> List.rev_map (fun t -> match t with | Branch(w, _) -> w | Leaf -> 0.) |> List.rev_map... |
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 -> let (cur_el, cur_num) = if hd = cur_el then (cur_el, cur_num + 1) else (hd, 1) in aux tl (cur_el, cur_num) (if cur_num > max_num then (cur_el, cur_num) else (max_el, max_n... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> raise Not_found | [_] -> raise Not_found | _ :: tl -> let zip a b = let rec aux a b acc = match (a, b) with | _, [] -> acc | [], _ -> acc | x :: a, y :: b -> aux a b ((x, y) :: acc) in List.rev (aux a b []) in mode (zip l tl) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let scalar = match from_unit, to_unit with | Hour, Second -> 3600. | Second, Hour -> 1. /. 3600. | _ -> 1. in (to_unit, val_ *. scalar) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let rec scalar from_unit to_unit = match from_unit, to_unit with | Mile, Foot -> 5280. | Foot, Meter -> 0.3048 | Mile, Meter -> (scalar Mile Foot) *. (scalar Foot Meter) | Foot, Mile | Meter, Foot | Meter, Mile -> 1. /. (scalar to_unit f... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (to_unit, val_ *. (snd (convert_dist ((fst from_unit), 1.) (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 rec passes_da_vinci t = let sum_of_squares l = l |> List.map (fun t -> match t with | Branch(f, _) -> f *. f | Leaf -> 0.) |> List.fold_left (+.) 0. in... |
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 -> let (cur_el, cur_num) = if hd = cur_el then (cur_el, cur_num + 1) else (hd, 1) in aux tl (cur_el, cur_num) (if cur_num > max_num then (cur_el, cur_num) else (max_el, max_n... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> raise Not_found | [_] -> raise Not_found | _ :: tl -> let zip a b = let rec aux a b acc = match (a, b) with | _, [] -> acc | [], _ -> acc | x :: a, y :: b -> aux a b ((x, y) :: acc) in List.rev (aux a b []) in mode (zip l tl) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let scalar = match from_unit, to_unit with | Hour, Second -> 3600. | Second, Hour -> 1. /. 3600. | _ -> 1. in (to_unit, val_ *. scalar) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let rec scalar from_unit to_unit = match from_unit, to_unit with | Mile, Foot -> 5280. | Foot, Meter -> 0.3048 | Mile, Meter -> (scalar Mile Foot) *. (scalar Foot Meter) | Foot, Mile | Meter, Foot | Meter, Mile -> 1. /. (scalar to_unit f... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let _, dist_scalar = convert_dist ((fst from_unit), 1.) (fst to_unit) in let _, time_scalar = convert_time ((snd from_unit), 1.) (snd to_unit) in (to_unit, val_ *. dist_scalar /. time_scalar) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let _, time = convert_time time (snd speed_unit) in (fst speed_unit, speed_val *. time) ;; let rec passes_da_vinci t = let sum_of_squares l = l |> List.rev_map (fun t -> match t with | Branch(f, _) -> f *. f | Leaf -> 0.) |> List.fo... |
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 aux xs... |
let pair_mode (l: 'a list) : 'a * 'a = let rec pair n l2 = match (n: int) with | n when n > 0 -> pair (n-1) ((List.nth l n)::l2) | 0 -> combine l l2 | _ -> notimplemented() in let new_list = List.rev((pair ((List.length l)-1) (List.nth l 0 :: []))) in mode(new_list) ;; |
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.))) |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 |Mile -> (to_unit, (val_/.5280.)) |Meter -> (to_unit, (val_*.0.3048)) |Foot -> (to_unit, val_) ) |Mile -> (match to_unit with |Mile -> (to_unit, val_) |Meter -> (to_unit, ((val_*.5280.)*.... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let time_value = convert_time ((snd from_unit), val_) (snd to_unit) in let dist_value = convert_dist ((fst from_unit), val_) (fst to_unit) in (to_unit,(val_ *. (snd dist_value /. snd time_value))) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let time_value = convert_time time (snd speed_unit) in ((fst speed_unit), ((snd time_value) *. speed_val)) ;; let rec passes_da_vinci t = let rec sum_ l acc = match l with |Branch(height, subtree)::tl -> if(passes_da_vinci (Branch(h... |
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 "Not a large enough list" | _::tl -> let listA = List.rev (List.tl (List.rev l)) in let listB = tl in let list = List.combine listA listB in mode list ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit = Hour then if to_unit = Hour then (Hour, val_) else (Second, val_ *. 3600.) else if to_unit = Second then (Second, val_) else (Hour, val_ /. 3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit = Foot then match to_unit with |Foot -> (Foot, val_) |Meter -> (Meter, val_ *. 0.3048) |_ -> (Mile, val_ /. 5280.) else if from_unit = Meter then 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 val2 = convert_dist (fst from_unit, val_) (fst to_unit) in let final = convert_time ((snd to_unit), snd val2) (snd from_unit) in (to_unit, snd final) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let v1 = convert_speed ( fst a, snd a) b_unit in (b_unit, (b_val +. (snd v1))) ;; |
let passes_da_vinci t = let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> if not ((check subtree) && ((sum_ subtree 0.) <= (width *. width))) then false else check tl in check [t] ;; |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | a ::( _ as r) -> if a = cur_el then if cur_num+1 > max_num then aux r (cur_el, cur_num+1) (cur_el, cur_num+1) else aux r (cur_el, cur_num+1) (max_el, max_num) else aux r ( a, 1) (max_... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Undefined input." | [x] -> failwith "Undefined input." | _ -> 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 -> ( to_unit , 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 , va... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist1, time1) = from_unit in let (dist2, time2) = to_unit in (to_unit, snd(convert_time ( time2, snd(convert_dist (dist1, val_) dist2)) time1)) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let t : time_unit =snd(speed_unit) in let time_converted :time_unit value = convert_time time t in (fst(speed_unit), speed_val *. snd( time_converted ) ) ;; let rec passes_da_vinci t = let rec sum_ l acc : float= match l with | [] -... |
let mode (l: 'a list) : 'a = let aux elem = (List.length (List.filter (fun x->x = elem) l), elem) in let pairs = List.sort (fun (a,_) (c,_) -> compare c a) (List.map aux l) in if l == [] then failwith "Empty list." else snd (List.hd (List.sort (fun (_,a) (_,c) -> compare a c) (List.filter (fun (x,_) -> x = fst (List.hd... |
let pair_mode (l: 'a list) : 'a * 'a = if l == [] then failwith "Empty 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 (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_ /. 0.3048) /. 5280.) | (Mile, Foot) -> ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((a,b),(c,d)) = (from_unit, to_unit) in ((fst (convert_dist (a, val_) c), fst (convert_time (b, val_) d)), val_ *. snd (convert_dist (a, val_) c) /. snd (convert_time (b, val_) d)) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (d_u, _) = speed_unit in let (time_u, time_val) = time in (d_u, snd (convert_speed (speed_unit, speed_val) (d_u, time_u)) *. time_val) ;; let rec passes_da_vinci t = let get_val = function | Branch (a,_) -> a | _ -> 0. in let re... |
let mode (l: 'a list) : 'a = let l1 = List.sort compare l in let rec aux l1 ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l1 with [] -> if (cur_num > max_num) then cur_el else max_el | h :: t -> if (h = cur_el) then if ((cur_num + 1) > max_num) then aux t (h, cur_num+1) (h, cur_num+1) else aux t... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = List.tl l in let l2 = List.rev (List.tl (List.rev l)) in let lc = List.combine l2 l1 in mode lc ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match 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 from_dist = fst(from_unit) in let from_time = snd(from_unit) in let to_dist = fst(to_unit) in let to_time = snd(to_unit) in let r1 = convert_dist (from_dist, val_) to_dist in let val1 = snd(r1) in let val2 = convert_time (to_time,... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_unit = fst(a) in let a_val = snd(a) in let a_convert = snd (convert_speed (a_unit, a_val) b_unit ) in let val_ = a_convert +. b_val in b_unit, val_ ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.