text stringlengths 0 601k |
|---|
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_/.1609.344) | Mil... |
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 (_,dist_val) = convert_dist (from_dist,val_) to_dist in let (_,time_ratio) = convert_time (from_time,1.) to_time in ((to_dist,to_time),dist_val/.time_rat... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (from_time_unit, time_val) = time in let (dist_unit, to_time_unit) = speed_unit in let (_,converted_time) = convert_time (from_time_unit,time_val) to_time_unit in dist_unit,(speed_val *. converted_time) ;; let width_subtree tree... |
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_num = -1 then aux xs (x,1)(x,1) else if x<>cur_el && cur_num>max_num then aux xs (x,1)(cur_el,cur_num) else if x<>cur_el && cur_num... |
let pair_mode (l: 'a list) : 'a * 'a = let rec create_tuples l acc = let get_tail l = match l with | _::t -> t | [] -> failwith "Was not supposed to happend" in match l with | a::b::_ -> create_tuples (get_tail l) ((a,b)::acc) | _ -> acc in mode (create_tuples 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 if from_unit = Hour then (Second, val_*.3600.) else (Hour, 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_/.1609.344) | Mil... |
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 (_,dist_val) = convert_dist (from_dist,val_) to_dist in let (_,time_ratio) = convert_time (from_time,1.) to_time in ((to_dist,to_time),dist_val/.time_rat... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (from_time_unit, time_val) = time in let (dist_unit, to_time_unit) = speed_unit in let (_,converted_time) = convert_time (from_time_unit,time_val) to_time_unit in dist_unit,(speed_val *. converted_time) ;; let width_subtree tree... |
let mode (l: 'a list) : 'a = if l = [] then notimplemented () else 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 = max_el || (x = cur_el && cur_num+1 > max_num) then aux (xs) (x, cur_num+1) (x, cur_num+1) els... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length (l) < 2 then notimplemented () else ( let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev (l))) in let pairs = List.combine (l2) (l1) in mode (pairs) ) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then notimplemented() else match from_unit with |Second -> if to_unit = Second then (Second, val_) else (Hour, val_/.3600.) |Hour -> if to_unit = Hour then (Hour, val_) else (Second, val_*.3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if val_ < 0. then notimplemented() else 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 = Meter then (Meter, val_) else ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then notimplemented() else let to_dist_val = snd (convert_dist (fst from_unit, val_) (fst to_unit)) in let to_time_val = snd (convert_time (snd from_unit, 1.) (snd to_unit)) in ((fst to_unit, snd to_unit), to_dist_val/.to... |
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 notimplemented () else let to_b_unit_val = snd (convert_speed (a) (b_unit)) in ((b_unit), b_val +. to_b_unit_val) ;; |
let passes_da_vinci t = iterate [t] ;; |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | x::xs -> if cur_el = x then aux xs (cur_el,cur_num + 1) (max_el,max_num) else if cur_num > max_num then aux xs (x,1) (cur_el,cur_num) else aux xs... |
let pair_mode (l: 'a list) : 'a * 'a = let rec duplicate l = match l with | x::xs::[] -> (x,xs) :: [] | x::y::ys -> (x,y) :: duplicate (y::ys) in let l = duplicate l in mode l ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,val_) with | (Second,t) -> (match to_unit with | Second -> (Second,t) | Hour -> (Second, t /. 3600.0) ) | (Hour,t) -> match to_unit with | Hour -> (Hour,t) | Second -> (Second, t *. 3600.0) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit,val_) with | (Foot,d) -> (match to_unit with | Foot -> (Foot,d) | Meter -> (Meter, d *. 0.3048) | Mile -> (Mile, d /. 5280.0 )) | (Meter,d) -> (match to_unit with | Meter -> (Meter, d) | Mile -> (Mile, (d /. 5280.0) /. 0... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist = convert_dist ((fst from_unit),val_) (fst to_unit) in let time = convert_time ((snd to_unit),(snd dist)) (snd from_unit) in (to_unit, (snd time)) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let ctime = convert_time ((fst time),(snd time)) (snd speed_unit) in ((fst speed_unit), ((snd ctime) *. speed_val)) ;; let sum_sq t = match t with | Leaf -> 0. | Branch (_,subtree) -> let rec children st = match st with | [] -> 0. |... |
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, c... |
let pair_mode (l: 'a list) : 'a * 'a = let rec temp l pairs= match l with | x :: y :: z -> temp (y::z) ((x,y)::pairs) | _ -> pairs in if List.length l < 2 then failwith "Inappropriate input." else mode (temp l []) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit=to_unit then (to_unit,val_) else if from_unit=Hour && to_unit=Second 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 | Meter -> if to_unit=Foot then (to_unit,val_ /. 0.3048) else (to_unit,val_ /. 0.3048 /. 5280.) | Foot -> if to_unit=Mile then(to_unit,val_ /. 5280.) else (to_unit,val_ *... |
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.0) (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,b_val+.snd(a)) else (b_unit,b_val+.snd(convert_speed(fst(a),snd(a)) (b_unit))) ;; |
let passes_da_vinci t= let rec temp l b acc width= match l with | [] -> acc <= width **2. | Leaf::tl -> temp tl b acc width | Branch (width1, subtree)::tl -> if temp subtree true 0. width1 then temp tl (b && (temp subtree true 0. width1)) (acc +. width1 ** 2.) width else false in match t with | Leaf -> true | Branch(wi... |
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 if (cur_num+1 > max_num) then aux (tl) (hd,cur_num+1) (cur_el,cur_num+1) else aux (tl) (hd,cur_num+1) (max_el,max_... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "invalid input" else let copy1 = (List.tl l) in let copy2 = List.rev (List.tl (List.rev l)) in mode(List.combine copy2 copy1) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Second, Second) | (Hour, Hour) -> to_unit,val_ | (Hour, Second) -> to_unit, val_ *. 3600. | (Second, Hour) -> to_unit, val_ /. 3600. ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match(from_unit, to_unit) with | (Foot, Foot) | (Meter, Meter) | (Mile, Mile)-> to_unit, val_ | (Foot, Meter)-> to_unit, val_ *. 0.3048 | (Foot, Mile)-> to_unit, val_ /. 5280. | (Meter, Foot)-> to_unit, val_ /. 0.3048 | (Meter, Mile)-> t... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let converted_distance = snd(convert_dist (fst(from_unit), val_) (fst(to_unit))) in let converted_time = snd(convert_time (snd(from_unit), 1.) (snd(to_unit))) in to_unit, converted_distance /. converted_time ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let copy = convert_speed (fst(a), snd(a)) (b_unit) in let sum = snd(copy) +. b_val in b_unit,sum ;; |
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.) <= (width*... |
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 max_el else cur_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) (cur_el,cur_num) else aux xs (x... |
let pair_mode (l: 'a list) : 'a * 'a = let rec pair_list l (lp: ('a * 'a) list) = match l with | [] -> failwith "emptyList" | [x] -> lp | x :: xs -> pair_list xs (List.append lp [(x,List.hd xs)]) in mode (pair_list l []) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit , to_unit with | Hour , Second -> (to_unit, val_ *. 3600.) | Second , Hour -> (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 -> (to_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (_, dist_converted_val) = convert_dist (fst from_unit, val_) (fst to_unit) in let (_, inv_factor) = convert_time (snd from_unit, 1.) (snd to_unit) in (to_unit, dist_converted_val /. inv_factor) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (dist_in_unit, time_speed_unit) = speed_unit in let (_, time_in_secunit) = convert_time time time_speed_unit in (dist_in_unit, speed_val *. time_in_secunit) ;; let rec passes_da_vinci t = let rec sum_sub li sum = match li 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 |l :: ls -> if cur_el = l then aux ls (cur_el, cur_num + 1) (max_el , max_num) else if cur_num > max_num then aux ls (l,1) (cur_el,cur_num) else aux... |
let pair_mode (l: 'a list) : 'a * 'a = let rec helper l x = match l with |[] -> failwith "Undefined input." |l1 :: [] -> failwith "Undefined input." |l1 :: l2 :: [] -> (l1,l2) :: x |l1 :: l2 :: ls -> helper (l2 :: ls) ((l1,l2) :: x) in let li = helper l [] in mode(li) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if from_unit != to_unit then match from_unit with |Second -> (to_unit, val_ /. 3600.) |Hour -> (to_unit , val_ *. 3600.) else (from_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if from_unit != to_unit then 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 /. 52... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (du, tu) = from_unit in let (tdu, ttu) = to_unit in let (tdu, v) = convert_dist (du, val_) tdu in let (tu, v1) = convert_time (ttu, v) tu in (to_unit, v1) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let(au,avl) = a in let(bu,v) = convert_speed (au,avl) b_unit in (b_unit, v +. b_val) ;; |
let passes_da_vinci t = let rec check l = match l with |[] -> true |Leaf :: ts -> true && check ts |Branch (v,ls) :: ts -> ((v *. v) >= (childsum ls)) && (check ls) && (check ts) in if t == Leaf then true else let Branch(v,l) = t in ((v *. v) >= (childsum l)) && check 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 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_e... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then notimplemented () else let copy1 = l in let copy2 = l in let _::t = copy1 in let l1 = t in let _::t = List.rev copy2 in let l2 = List.rev t in mode (List.combine l2 l1) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_), 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, val_), 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 /. ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((_, _), _), _ = (from_unit, val_), to_unit in (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 = (b_unit, snd (convert_speed ((fst a), (snd a)) b_unit) +. b_val) ;; |
let passes_da_vinci t = let rec summation l acc = match l with | [] -> acc | Leaf :: tail -> summation tail acc | Branch (width, subtree) :: tail -> summation tail (acc +. (width *. width)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if (check subtree && su... |
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 = to_unit then (from_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 = 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.3048/.5280... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (from_unit,val_) else if fst(from_unit) = fst(to_unit) then (to_unit, snd(convert_time (snd(to_unit), val_) (snd(from_unit)))) else if snd(from_unit) = snd(to_unit) then (to_unit, snd(convert_dist (fst(from... |
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 acc w= match l with | [] -> acc <= (w ** 2.) | Leaf :: tl -> check tl acc w | Branch (width, subtree) :: tl -> if not (check subtree 0. width) then false else check tl (acc+.width**2.) w in match t with | Leaf -> true | Branch(width, subtree) -> check subtree 0. width ;; |
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 = to_unit then (from_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 = 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.3048/.5280... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (from_unit,val_) else if fst(from_unit) = fst(to_unit) then (to_unit, snd(convert_time (snd(to_unit), val_) (snd(from_unit)))) else if snd(from_unit) = snd(to_unit) then (to_unit, snd(convert_dist (fst(from... |
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 acc w= match l with | [] -> acc <= (w**2.) | Leaf :: tl -> check tl acc w | Branch (width, subtree) :: tl -> if not (check subtree 0. width) then false else check tl (acc+.width**2.) w in match t with | Leaf -> true | Branch (width, subtree) -> check subtree 0. width ;; |
let mode (l: 'a list) : 'a = match List.sort compare l with | [] -> failwith "Error" | x::xs -> 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... |
let pair_mode (l: 'a list) : 'a * 'a = let rec helper l acc = match l with | x::y::xs -> helper (y::xs) ((x,y)::acc) | _ -> acc in mode (helper 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.) | (Second, Second) -> (Second, val_) | (Hour, Hour) -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let helper from_unit val_ = match from_unit with | Foot -> val_ | Meter -> val_/.0.3048 | Mile -> val_*.5280. in match to_unit with | Foot -> (Foot, (helper from_unit val_)) | Meter -> (Meter, (helper from_unit val_)*.0.3048) | Mile -> (... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d1, t1) = from_unit in let (d2, t2) = to_unit in let (d2, dval) = convert_dist (d1, val_) d2 in let (t2, fval) = convert_time (t2, dval) t1 in ((d2,t2), fval) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (s_dist, s_time) = speed_unit in let (t_unit, t_val) = convert_time time s_time in (s_dist, t_val *. speed_val) ;; let tree_example2 = Branch (5., []);; let tree_example3 = Branch (5., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Br... |
let mode (l: 'a list) : 'a = let emptylist() = failwith "The list is empty, there is no most common element" 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 (cur_el,cur_num+1) (max_el, ... |
let pair_mode (l: 'a list) : 'a * 'a = let error() = failwith "input should be a list of at least 2 elements" in let rec createpairs l = match l with |x::y::[] -> (x,y):: []; |x::y::xs -> (x,y) :: (createpairs (y::xs)); in match l with |[] -> error(); |[x] -> error(); |x::xs -> mode (createpairs l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let error() = failwith "not correct input" in match (from_unit, val_) with |Second, y -> (match to_unit with |Hour -> to_unit, y /. 3600.; |Second -> to_unit, y;) |Hour, y -> (match to_unit with |Second -> to_unit, y *. 3600.; |Hour -> t... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let error() = failwith "not correct input" in match (from_unit, val_) with |Foot, y -> (match to_unit with |Meter -> to_unit, y *. 0.3048; |Mile -> to_unit, y /. 5280.; |Foot -> to_unit, y;) |Meter, y -> (match to_unit with |Foot -> to_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let error() = failwith "not correct input" in match (from_unit, val_) with |(Foot,Hour), y-> (match to_unit with |(Meter,Hour) -> to_unit, y *. 0.3048; |(Meter,Second) -> to_unit, y *. 0.3048 /. 3600.; |(Mile, Hour) -> to_unit, y /. 5... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = match (speed_unit, speed_val) with |((_ ,Second),y) -> (let time = convert_time time Second in match speed_unit, time with |(Mile ,Second ), (Second, x)-> (Mile, (y *. x)) |(Foot ,Second ), (Second, x)-> (Foot, (y *. x)) |(Meter ,Se... |
let mode (l: 'a list) : 'a = let emptylist() = failwith "The list is empty, there is no most common element" 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 (cur_el,cur_num+1) (max_el, ... |
let pair_mode (l: 'a list) : 'a * 'a = let error() = failwith "input should be a list of at least 2 elements" in let rec createpairs l = match l with |x::y::[] -> (x,y):: []; |x::y::xs -> (x,y) :: (createpairs (y::xs)); in match l with |[] -> error(); |[x] -> error(); |x::xs -> mode (createpairs l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let error() = failwith "not correct input" in match (from_unit, val_) with |Second, y -> (match to_unit with |Hour -> to_unit, y /. 3600.; |Second -> to_unit, y;) |Hour, y -> (match to_unit with |Second -> to_unit, y *. 3600.; |Hour -> t... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let error() = failwith "not correct input" in match (from_unit, val_) with |Foot, y -> (match to_unit with |Meter -> to_unit, y *. 0.3048; |Mile -> to_unit, y /. 5280.; |Foot -> to_unit, y;) |Meter, y -> (match to_unit with |Foot -> to_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let error() = failwith "not correct input" in match (from_unit, val_) with |(Foot,Hour), y-> (match to_unit with |(Meter,Hour) -> to_unit, y *. 0.3048; |(Meter,Second) -> to_unit, y *. 0.3048 /. 3600.; |(Mile, Hour) -> to_unit, y /. 5... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = match (speed_unit, speed_val) with |((_ ,Second),y) -> (let time = convert_time time Second in match speed_unit, time with |(Mile ,Second ), (Second, x)-> (Mile, (y *. x)) |(Foot ,Second ), (Second, x)-> (Foot, (y *. x)) |(Meter ,Se... |
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 when hd = cur_el -> aux tl (cur_el, cur_num + 1) (max_el, max_num) | hd::tl -> 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 "list is empty" | x::[] -> failwith "list must have at least two elements" | _ -> (mode ((to_tuples l) @ (to_tuples (List.tl l)))) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with (Hour, Second) -> (Second, (val_ *. 3600.)) | (Second, Hour) -> (Hour, (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) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Mile) -> (Mile, (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 let speed_val = convert_dist (fst from_unit, val_) (fst to_unit) in let time_val = convert_time (snd from_unit, 1.) (snd to_unit) in (to_unit, snd speed_val /. snd time_val) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let new_speed = convert_speed (speed_unit, speed_val) (fst speed_unit, fst time) in (fst speed_unit, snd new_speed *. (snd time)) ;; let sum_squares (l: tree list) : float = let rec helper_sum (l: tree list) (sum_so_far: float) : fl... |
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 when hd = cur_el -> aux tl (cur_el, cur_num + 1) (max_el, max_num) | hd::tl -> if cur_num > max_num then aux tl (hd, 1) (cur_el, cur_num) ... |
let pair_mode (l: 'a list) : 'a * 'a = (mode ((to_tuples l) @ (to_tuples (List.tl l)))) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with (Hour, Second) -> (Second, (val_ *. 3600.)) | (Second, Hour) -> (Hour, (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) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Mile) -> (Mile, (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 let speed_val = convert_dist (fst from_unit, val_) (fst to_unit) in let time_val = convert_time (snd from_unit, 1.) (snd to_unit) in (to_unit, snd speed_val /. snd time_val) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let new_speed = convert_speed (speed_unit, speed_val) (fst speed_unit, fst time) in (fst speed_unit, snd new_speed *. (snd time)) ;; let sum_squares (l: tree list) : float = let rec helper_sum (l: tree list) (sum_so_far: float) : fl... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.