text stringlengths 0 601k |
|---|
let pair_mode (l: 'a list) : 'a * 'a = match l with |[]->failwith "Empty list" |hd::[]->failwith "Only 1 element" |_ -> 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 |(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_unit, val_ *... |
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 add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, snd(convert_speed a b_unit) +. b_val ) ;; |
let passes_da_vinci t = let rec 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**2.))) then check tl e... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | x:: xs -> if (x <> cur_el) then aux xs (x, 1) (max_el, max_num) else if (x = cur_el && cur_num+ 1 > max_num) then aux xs (x, cur_num+ 1) (x, cur_num+ 1) else aux xs (x, cur_num+ 1) (m... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> notimplemented () | _:: l0 -> match l0 with |[] -> notimplemented () |_ -> match (List.rev l) with |[] -> notimplemented () | _:: l3 -> let l2= List.rev l3 in let aList= List.combine l2 l0 in mode aList ;; |
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.) | u, _ -> (u, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Mile -> (Mile, val_ /. 5280.) | Foot, Meter -> (Meter, val_ *. 0.3048) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. (0.3048 *. 5280.)) | Mile, Foot -> (Foot, val_ *. 5280.)... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d1, t1), (d2, t2)= from_unit, to_unit in let (_, dis)= convert_dist (d1, 1.) d2 in let (_, tim)= convert_time (t1, 1.) t2 in ((d2, t2), val_ *. dis /. tim) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (du0, tu0)= speed_unit in let (_, tv1)= convert_time time tu0 in (du0, tv1 *. speed_val) ;; let rec sumTreeList trList= match trList with | [] -> 0. | x:: xs -> match x with | Leaf -> sumTreeList xs | Branch (f, _) -> f *.f +. s... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | x:: xs -> if (x <> cur_el) then aux xs (x, 1) (max_el, max_num) else if (x = cur_el && cur_num+ 1 > max_num) then aux xs (x, cur_num+ 1) (x, cur_num+ 1) else aux xs (x, cur_num+ 1) (m... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> notimplemented () | _:: l0 -> match l0 with |[] -> notimplemented () |_ -> match (List.rev l) with |[] -> notimplemented () | _:: l3 -> let l2= List.rev l3 in let aList= List.combine l2 l0 in mode aList ;; |
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.) | u, _ -> (u, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Mile -> (Mile, val_ /. 5280.) | Foot, Meter -> (Meter, val_ *. 0.3048) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. (0.3048 *. 5280.)) | Mile, Foot -> (Foot, val_ *. 5280.)... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (d1, t1), (d2, t2)= from_unit, to_unit in let (_, dis)= convert_dist (d1, 1.) d2 in let (_, tim)= convert_time (t1, 1.) t2 in ((d2, t2), val_ *. dis /. tim) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (du0, tu0)= speed_unit in let (_, tv1)= convert_time time tu0 in (du0, tv1 *. speed_val) ;; let rec sumTreeList trList= match trList with | [] -> 0. | x:: xs -> match x with | Leaf -> sumTreeList xs | Branch (f, _) -> f *.f +. s... |
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 au... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = l in let l2 = List.rev l in let helper (l: 'a list) : 'a list= match l with | x::xs -> xs | _ -> failwith "Please enter a valid list" in let l1 = helper l1 in let l2 = List.rev (helper l2) in mode (List.combine l2 l1) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if fst(from_unit,val_) = to_unit then (from_unit,val_) else match fst (from_unit, val_) with | Hour -> (Second, (val_ *. 3600.)) | Second -> (Hour, (val_ /. 3600.)) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if fst(from_unit,val_) = to_unit then (from_unit,val_) else match fst (from_unit, val_) with | Foot -> ( match to_unit with | Meter -> (Meter, val_ *. 0.3048) | Mile -> (Mile, val_ /. 5280.) ) | Meter -> ( match to_unit with | Foot -> (F... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let middle = convert_dist ((fst(from_unit)), val_) (fst(to_unit)) in let finish = convert_time ((snd(from_unit)), 1. /. (snd(middle))) (snd(to_unit)) in (to_unit, (1. /. snd(finish))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let middle = convert_speed a b_unit in (b_unit, (snd(middle)) +. b_val) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | Branch (width, subtree) :: xs -> (sum_ xs acc +. width *. width) | Leaf :: xs -> sum_ xs acc | _ -> acc in let rec check l = match l with |[] -> true |Branch (width, subtree)::xs -> if width *. width < sum_ subtree 0. then false else (if not (check subtree) th... |
let rec mode (l: 'a list) : 'a = let list = List.sort compare (l : 'a list) in match list with |[] -> failwith "List is empty" |hd::t -> let rec aux list ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match list with |[] -> if cur_num > max_num then cur_el else max_el |x::xs when x = cur_el -> if cur_n... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "List is empty" | _::[] -> failwith "Not enough elements" | _::t -> let l1 = List.tl l in let l2 = List.rev ( List.tl (List.rev l)) in let list = List.combine l2 l1 in mode list ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match fst(from_unit, val_) with | Second -> (match to_unit with |Second -> (to_unit, snd(from_unit, val_)) |Hour -> (to_unit, (snd(from_unit, val_) /. 3600.0) ) ) | Hour -> (match to_unit with |Hour -> (to_unit, snd(from_unit, val_)) |Se... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match fst(from_unit, val_) with | Foot -> (match to_unit with |Foot -> (to_unit, snd(from_unit, val_)) |Meter -> (to_unit, snd(from_unit, val_) *. 0.3048) |Mile -> (to_unit, snd(from_unit, val_) /. 5280.0) ) | Meter -> (match to_unit wit... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distanceFrom = fst(fst(from_unit, val_)) in let timeFrom = snd(fst(from_unit, val_)) in let distanceTo = fst(to_unit) in let timeTo = snd(to_unit) in let value = snd(from_unit, val_) in let newValue = snd((convert_dist (distanceFr... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed = fst(speed_unit, speed_val) in let desiredUnit = fst(speed) in let desiredTime = snd(speed) in let correctTime = convert_time time desiredTime in let distanceTravelled = snd(speed_unit, speed_val) *. snd(correctTime) in (... |
let rec mode (l: 'a list) : 'a = let list = List.sort compare (l : 'a list) in match list with |[] -> failwith "List is empty" |hd::t -> let rec aux list ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match list with |[] -> if cur_num > max_num then cur_el else max_el |x::xs when x = cur_el -> if cur_n... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "List is empty" | _::[] -> failwith "Not enough elements" | _::t -> let l1 = List.tl l in let l2 = List.rev ( List.tl (List.rev l)) in let list = List.combine l2 l1 in mode list ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match fst(from_unit, val_) with | Second -> (match to_unit with |Second -> (to_unit, snd(from_unit, val_)) |Hour -> (to_unit, (snd(from_unit, val_) /. 3600.0) ) ) | Hour -> (match to_unit with |Hour -> (to_unit, snd(from_unit, val_)) |Se... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match fst(from_unit, val_) with | Foot -> (match to_unit with |Foot -> (to_unit, snd(from_unit, val_)) |Meter -> (to_unit, snd(from_unit, val_) *. 0.3048) |Mile -> (to_unit, snd(from_unit, val_) /. 5280.0) ) | Meter -> (match to_unit wit... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let distanceFrom = fst(fst(from_unit, val_)) in let timeFrom = snd(fst(from_unit, val_)) in let distanceTo = fst(to_unit) in let timeTo = snd(to_unit) in let value = snd(from_unit, val_) in let newValue = snd((convert_dist (distanceFr... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed = fst(speed_unit, speed_val) in let desiredUnit = fst(speed) in let desiredTime = snd(speed) in let correctTime = convert_time time desiredTime in let distanceTravelled = snd(speed_unit, speed_val) *. snd(correctTime) in (... |
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 | [] -> max_el | h :: t -> if h = cur_el then if h = max_el then aux t ((cur_el, (cur_num+1)) : 'a * int) ((max_el, (max_num+1)) : 'a * int) else if ((cur_num+1)>max_num... |
let pair_mode (l: 'a list) : ('a * 'a) = match l with | [] -> failwith "list too short" | h :: [] -> failwith "list too short" | _ -> let rec removelast (l: 'a list) (l2: 'a list): ('a list) = match l with | [] -> failwith "error" | h :: [] -> List.rev l2 | h :: t -> removelast t (h::l2) in let list_no_last = removelas... |
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.)) | (Mile, Foot) -> (to_unit, (val_ *. 5280.)) | (Mile, Meter) -> (to_unit, (val_ *. 5280. *. 0.3048)) | (Meter, Fo... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (from_dist_unit, from_time_unit) = from_unit in let (to_dist_unit, to_time_unit) = to_unit in let (dist_unit, value1) = (convert_dist (from_dist_unit, val_) to_dist_unit) in let (time_unit, value2) = (convert_time (from_time_unit,... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (arg1_speed, arg1_val) = convert_speed a b_unit in (b_unit, (arg1_val +. 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. <... |
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 | e::t -> if cur_el = e then aux t (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux t (e,1) (cur_el, cur_num) else aux t ... |
let pair_mode (l: 'a list) : 'a * 'a = let rec bilist l = match l with |[] -> failwith "list is empty" |e::[] -> [] |e::r::t -> [(e,r)]@(bilist (r::t)) in mode (bilist l) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with |Second -> if to_unit = from_unit then (Second, val_) else (Hour, val_ /. 3600. ) |Hour -> if to_unit = from_unit then (Hour, 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 = from_unit then (Foot, val_) else if to_unit = Meter then (Meter, val_ *. 0.3048) else (Mile, val_ /. 5280.) |Meter -> if to_unit = from_unit then (Meter, val_) else if to_unit = Foot then (Foot,... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit with |(Foot, Second) -> if to_unit = from_unit then ((Foot,Second),val_) else if to_unit = (Foot, Hour) then ((Foot, Hour), val_ *. 3600.) else if to_unit = (Meter, Second) then ((Meter, Second), val_ *. 0.3048) else i... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let gethim (a,_) = a in let gethimm (_,a) = a in let u = gethim speed_unit in let p = gethim time in let z = gethimm speed_unit in if p = z then let (r,t) = time in (u, (t *. speed_val)) else begin let b = convert_time time z in let... |
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 (compare x cur_el = 0 && cur_num + 1 > max_num) then aux xs (x, cur_num) (cur_el, cur_num + 1) else if compare x cur_el = 0 then au... |
let pair_mode (l: 'a list) : 'a * 'a = if l == [] then failwith "This function does not take empty lists as input." else let l1 = List.tl (l) and 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 = match to_unit with | Second -> if from_unit = Hour then (Second, (val_ *. 3600.0)) else (Second, val_ ) | Hour -> if from_unit = Second then (Hour, (val_ /. 3600.0)) else (Hour, val_ ) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> if from_unit = Meter then (Foot, (val_ /. 0.3048)) else if from_unit = Mile then (Mile, (val_ *. 5280.0)) else (from_unit, val_) | Meter -> if from_unit = Foot then (Meter, val_ *. 0.3048) else if from_unit =... |
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.0) (snd(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 a b_unit)) ;; |
let passes_da_vinci t = let rec sum_ (l: tree list) : float = match l with | Leaf :: tl -> 0. +. sum_ tl | [] -> 0. | Branch (x, y) :: tl -> (x *. x) +. sum_ tl in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> if not ((check subtree) && (sum_ subtree <= (width *. wi... |
let error() = failwith "Incompatible list length";; |
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 (h, (cur_num + 1)) (cur_el, (cur_num + 1)) else aux t (h, (cur_num + 1)) (max_el, max_num) else aux t (h, 1) (max_el, max... |
let pair_mode l = let rec aux l pairs = match l with |_::[] -> pairs |h::m::t-> aux (m::t) ((h,m) :: pairs) in match l with |[] -> error() |[_] -> error() | _ -> mode(aux l []) ;; let secInHour = 3600.;; |
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_ /. secInHour)) |Hour, Second -> (to_unit, (val_ *. secInHour)) |_,_ -> (to_unit, val_) ;; let metersInFoot = 0.3048 let feetInMile = 5280.;; |
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_ *. metersInFoot)) |Foot,Mile -> (to_unit, (val_ /. feetInMile)) |Meter,Foot -> (to_unit, (val_ /. metersInFoot)) |Meter,Mile -> (to_unit, (val_ /. metersInFoot /. feetInMile)) ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist,t),(dist',t') = from_unit, to_unit in let (_,convertedDist) = convert_dist (dist, val_) dist' in let (_,convertedTime) = convert_time (t, 1.) t' in (to_unit, convertedDist /. convertedTime) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (d,t') = speed_unit in let (_, convertedTime) = convert_time time t' in (d,convertedTime *. speed_val) ;; let rec sumOfSquares list = match list with |[] -> 0. |Leaf::t -> 0. +. sumOfSquares t |Branch(diameter,_)::t -> diameter*... |
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 let (new_max_el, new_max_num) = if cur_num > max_num then (cur_el, ... |
let pair_mode (l: 'a list) : 'a * 'a = let rec get_bigram l = match l with | h1 :: h2 :: t -> (h1, h2) :: (get_bigram (h2::t)) | _ -> [] in mode (get_bigram 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.0) | (Hour, Second) -> (to_unit, val_ *. 3600.0) | _ -> (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, 0.3048 *. val_) | (Foot, Mile) -> (to_unit, val_ /. 5280.0) | (Meter, Foot) -> (to_unit, val_ /. 0.3048) | (Meter, Mile) -> (to_unit, val_ /. 0.3048 /. 5280.0) | (Mile, Foot) -... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_unit_dist, from_unit_time), (to_unit_dist, to_unit_time)) = (from_unit, to_unit) in let (_, dis_val) = convert_dist (from_unit_dist, val_) to_unit_dist in let (_, time_val) = convert_time (from_unit_time, 1.0) to_unit_time ... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let ((s_dis_unit, s_time_unit), (t_unit, t_val)) = (speed_unit, time) in let (_, new_speed) = convert_speed (speed_unit, speed_val) (s_dis_unit, t_unit) in (s_dis_unit, new_speed *. t_val) ;; let tree_example2 = Branch (4., [ Branch... |
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 && cur_num+1<= max_num then aux xs (x,cur_num+1) (max_el,max_num) else if x= cur_el &&cur_num+1>max_num then aux xs (x,cur_num+1)... |
let pair_mode (l: 'a list) : 'a * 'a = let rec copy list1 list2= match list1 with |[]->list2 |x::xs->x::(copy xs list2) in let cut list = match list with |[]->list |x::xs->xs in let list1=[] in let list1=copy l list1 in let new_1=cut list1 in let list2= [] in let list2= copy l list2 in let rev_list2 = List.rev list2 in... |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with |Second-> if from_unit = Second then (Second,val_) else (Second, (3600.*. val_)) |Hour->if from_unit = Hour then (Hour,val_) else (Hour,(val_/.3600.)) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with |Foot->if from_unit = Foot then (Foot,val_) else if from_unit = Meter then (Foot, val_/.0.3048) else (Foot,val_*.5280. ) |Meter->if from_unit = Meter then (Meter,val_) else if from_unit=Foot then (Meter,val_*.0.3048) e... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match to_unit with |(Foot,Second)-> if from_unit=(Foot,Hour) then ((Foot,Second),val_/.3600.) else if from_unit = (Meter,Second) then ((Foot,Second),snd(convert_dist (Meter,val_) Foot)) else if from_unit =( Meter,Hour) then ((Foot,Sec... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let new_speed1 = convert_speed a b_unit in let result_speed = snd(new_speed1) +. b_val in (b_unit,result_speed) ;; |
let passes_da_vinci t = let rec sum_ l acc= match l with |[]-> acc |Leaf::tl-> sum_ tl (acc+.0.) |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 width*.width >= (sum_ subtree 0.) then check subtree else false in che... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | x :: xs -> if cur_el = x then aux xs (cur_el, 1 + cur_num) (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 = let b_l = build_list l in mode b_l ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (match to_unit with | Hour -> (Hour, val_ /. 3600.) | Second -> (Second, val_)) | 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 (_, val_1) = convert_time ((second_element from_unit), 1.) (second_element to_unit) in let (_, val_2) = convert_dist ((first_element from_unit), val_) (first_element to_unit) in to_unit, val_2 /. val_1 ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (_, val_1) = convert_speed a b_unit in (b_unit, val_1 +. 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 ** 2.) in let rec check list = match list with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if sum_ subtree 0. > width ** 2. then false el... |
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 :: xs -> if cur_el = hd then aux xs (cur_el, cur_num+1) (max_el,max_num) else if cur_num > max_num then aux xs (hd, 1) (cur_el,cur_num) else a... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = l in let l2= l in let (_ :: l1_c ) = l in let (_ :: l2_t ) = List.rev l in let l2_c = List.rev l2_t in let l_combined = List.combine l2_c l1_c in mode l_combined ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) 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 = match (from_unit, val_) 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 if to_unit = Foot ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist_ = snd (convert_dist (fst from_unit, val_) (fst to_unit)) in let inv_ = snd (convert_time (snd from_unit, 1.) (snd to_unit)) in (to_unit, dist_ /. inv_) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, b_val +. snd(convert_speed a b_unit) ) ;; |
let passes_da_vinci t = let rec sum_square l sum= match l with | [] -> sum | x ::xs -> ( match x with | Leaf -> sum_square xs sum | Branch (y,_)-> sum_square xs sum +. y *. y ) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not (check subtree && width *. wi... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = notimplemented () in match List.sort compare l with | [] -> failwith "Error: empty list" | [x] -> x | x::xs -> x ;; |
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, to_unit with | Second, Second -> (Second, val_) | Second, Hour -> (Hour, val_ /. 3600.0) | Hour, Second -> (Second, val_ *. 3600.0) | Hour, Hour -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Meter, Foot -> (Foot, val_ /. 0.3048); | Meter, Mile -> (Mile, val_ /. 1609.344); | Foot, Meter -> (Meter, val_ *. 0.3048); | Foot, Mile -> (Mile, val_ /. 5280.0); | Mile, Foot -> (Foot, val_ *. 5280.0); |... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let old_time_unit : time_unit = snd(from_unit) in let new_time_unit : time_unit = snd(to_unit) in let old_dist_unit : dist_unit = fst(from_unit) in let new_dist_unit : dist_unit = fst(to_unit) in let new_time : float = snd(convert_tim... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let speed_a_converted = convert_speed (a) b_unit in let new_speed_a_val : float = snd(speed_a_converted) in (b_unit, new_speed_a_val +. b_val) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> acc | Branch (width, subtree) :: tl -> sum_ subtree (width*.width +. acc) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not ((check subtree) && ((sum_ subtree 0.) <= (wid... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | hd :: tl -> if hd = cur_el && cur_num + 1 <= max_num then aux tl (cur_el, cur_num+1) (max_el, max_num) else if hd = cur_el && cur_num + 1 > max_num then aux tl (cur_el, cur_num+1) (cu... |
let pair_mode (l: 'a list) : 'a * 'a = let rec copy_l (l1: 'a list) (l2: ('a * 'a) list) : ('a * 'a) list = match l1 with | [] -> failwith "It doesn't work" | h::t -> if (List.length l1)> 1 then copy_l t (List.append [(h,(List.hd t))] l2) else l2 in if (List.length l >= 2) then mode (copy_l l []) else failwith "It does... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.