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 | [] -> max_el | f::h -> if f = cur_el then if cur_num = max_num then aux h (f, (cur_num + 1)) (f, cur_num + 1) else aux h (f, (cur_num + 1)) (max_el, max_num) else if max_num = 0 then aux h (f, 1) (f... |
let pair_mode (l: 'a list) : 'a * 'a = let rec get_pair l acc = match l with | [] -> acc | f::h -> match h with | [] -> acc | a::_ -> get_pair h ((f, a)::acc) in mode (get_pair 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.) | _ -> (from_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot , Meter) -> (Meter, val_ *. 0.3048) | (Meter , Foot) -> (Foot, val_ /. 0.3048) | (Foot , Mile) -> (Mile, val_ /. 5280.0) | (Mile , Foot) -> (Foot, val_ *. 5280.0) | (Meter , Mile) -> (Mile, val_ /.... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist, from_time),(to_dist, to_time)) = (from_unit, to_unit) in ( let (_, con_dist),(_, con_time) = (convert_dist (from_dist, 1.) to_dist , convert_time (from_time, 1.) to_time) in ((to_dist, to_time), val_ *. (con_dist /. c... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_dist, speed_time) = speed_unit in( let (_, con_time_val) = convert_time time speed_time in (speed_dist, (con_time_val *. speed_val)) ) ;; let rec passes_da_vinci t = let rec aux width l sum = match l with | [] -> sum <= (... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | f::h -> if f = cur_el then if cur_num = max_num then aux h (f, (cur_num + 1)) (f, cur_num + 1) else aux h (f, (cur_num + 1)) (max_el, max_num) else if max_num = 0 then aux h (f, 1) (f... |
let pair_mode (l: 'a list) : 'a * 'a = let rec get_pair l acc = match l with | [] -> acc | f::h -> match h with | [] -> acc | a::_ -> get_pair h ((f, a)::acc) in mode (get_pair 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.) | _ -> (from_unit, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot , Meter) -> (Meter, val_ *. 0.3048) | (Meter , Foot) -> (Foot, val_ /. 0.3048) | (Foot , Mile) -> (Mile, val_ /. 5280.0) | (Mile , Foot) -> (Foot, val_ *. 5280.0) | (Meter , Mile) -> (Mile, val_ /.... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((from_dist, from_time),(to_dist, to_time)) = (from_unit, to_unit) in (let (_, con_dist),(_, con_time) = (convert_dist (from_dist, 1.) to_dist , convert_time (from_time, 1.) to_time) in ((to_dist, to_time), val_ *. (con_dist /. co... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_dist, speed_time) = speed_unit in( let (_, con_time_val) = convert_time time speed_time in (speed_dist, (con_time_val *. speed_val)) ) ;; let rec passes_da_vinci t = let rec aux width l sum = match l with | [] -> sum <= (... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | el::tl -> if cur_num > max_num then aux tl (el, 1) (cur_el, cur_num) else if el = cur_el then aux tl (el, cur_num + 1) (max_el, max_num) else aux tl (el, 1) (max_el, max_num) | [] -> if cur_num > ma... |
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 | Hour, Second -> Second, (val_ *. 3600.) | Second, Hour -> Hour, (val_ /. 3600.) | Hour, Hour -> Hour, val_ | Second, Second -> Second, val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Mile, Foot -> Foot, val_ *. 5280. | Foot, Mile -> Mile, val_ /. 5280. | Mile, Meter -> Meter, val_ *. 5280. *. 0.3048 | Meter, Mile -> Mile, val_ /. (5280. *. 0.3048) | Foot, Meter -> Meter, val_ *. 0.3048... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let time = convert_time (snd(from_unit), 1.) (snd(to_unit)) in let dist = convert_dist ((fst(from_unit)), val_) (fst(to_unit)) in ((fst(dist), fst(time)), snd(dist) /. snd(time)) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let time2 = convert_time time (snd(speed_unit)) in (fst(speed_unit), (snd(time2) *. speed_val)) ;; let tree_example2 = Leaf;; let tree_example3 = Branch (1., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (4., []) ]) ;; let rec squ... |
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 max_num >= cur_num then max_el else cur_el | hd::tl -> ( if hd = cur_el then aux tl (hd,cur_num+1) (max_el, max_num) else ( if max_num >= cur_num then aux tl (hd, 1) (max_el, max_num) else ... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "error! the list cannot be empty" | hd::tl -> let inv_tail = List.tl (List.rev l) in let l1 = List.rev inv_tail in let l2 = List.tl l in let all_pairs = List.combine l1 l2 in mode all_pairs ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Second, Second -> (Second, val_) | Hour, Second -> (Second, val_ *. 3600.) | Hour, Hour -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Foot, Mile -> (Mile, val_ /. 5280.) | Foot, Meter -> (Meter, val_ *. 0.3048) | Mile, Foot -> (Foot, val_ *. 5280.) | Mile, Mile -> (Mile, val_) | Mile, Meter -> (Meter, val_ *.... |
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 (to_dist, converted_dist) = convert_dist (from_dist, val_) to_dist in let (to_time, converted_time) = convert_time (from_time, 1.) to_time in (to_dist, ... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (a_unit, a_val) = a in let (converted_unit, converted_val) = convert_speed (a_unit, a_val) (b_unit) in (b_unit), (converted_val +. b_val) ;; |
let passes_da_vinci t = let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if (sum_of_squares subtree 0. <= width *. width) && check subtree then check tl else false in check [t] ;; |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | el::tl -> if el = cur_el then aux tl (el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux tl (el, 1) (cur_el, cur_num) else aux tl (el, 1) (max_el, max_num) | [] -> if cur_num > ma... |
let pair_mode (l: 'a list) : 'a * 'a = let _, l' = List.fold_left (fun (last, acc) i -> match last with | None -> Some i, acc | Some last -> Some i, (last, i) :: acc) (None, []) l in mode 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.) | _ -> from_unit, val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let new_val = match from_unit, to_unit with | Mile, Foot -> val_ *. 5280. | Mile, Meter -> val_ *. 1609.344 | Meter, Mile -> val_ /. 1609.344 | Meter, Foot -> val_ /. 0.3048 | Foot, Meter -> val_ *. 0.3048 | Foot, Mile -> val_ /. 5280. |... |
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 to_time', time_scale = convert_time (from_time, 1.) to_time in let to_dist, dist_scale = convert_dist (from_dist, val_) to_dist in (to_dist, to_time'), (dis... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let dist_unit, time_unit = speed_unit in let _, time = convert_time time time_unit in let distance = speed_val *. time in dist_unit, distance ;; let rec passes_da_vinci t = let square v = v *. v in let rec sum_of_squares tree_list =... |
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 | el::tl -> if el = cur_el then aux tl (el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux tl (el, 1) (cur_el, cur_num) else aux tl (el, 1) (max_el, max_num) | [] -> if cur_num > ma... |
let pair_mode (l: 'a list) : 'a * 'a = let _, l' = List.fold_left (fun (last, acc) i -> match last with | None -> Some i, acc | Some last -> Some i, (last, i) :: acc) (None, []) l in mode 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.) | _ -> from_unit, val_ ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let new_val = match from_unit, to_unit with | Mile, Foot -> val_ *. 5280. | Mile, Meter -> val_ *. 1609.344 | Meter, Mile -> val_ /. 1609.344 | Meter, Foot -> val_ /. 0.3048 | Foot, Meter -> val_ *. 0.3048 | Foot, Mile -> val_ /. 5280. |... |
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 to_time', time_scale = convert_time (from_time, 1.) to_time in let to_dist, dist_scale = convert_dist (from_dist, val_) to_dist in (to_dist, to_time'), (dis... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let dist_unit, time_unit = speed_unit in let _, time = convert_time time time_unit in let distance = speed_val *. time in dist_unit, distance ;; let rec passes_da_vinci t = let square v = v *. v in let rec child_sum l acc = match l ... |
let mode (l: 'a list) : 'a = match l with | [] -> failwith "empty list" | hd::_ -> let rec aux l ((cur_el,cur_num) : ('a * int)) ((max_el,max_num) : ('a * int)) = match (l, (cur_el, cur_num), (max_el, max_num)) with | ([],_,_) -> max_el | (x::xs,(_,_),(_,0)) -> aux xs (x, 1) (x, 1) | (x::xs,(_,_),(m,_)) when x = m -> a... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "list empty or too short" else mode (List.combine (rem_tail l) (rem_head l) );; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_), to_unit with | (Second, v) , Second -> (Second, v) | (Second, v) , Hour -> (Hour, v /. 3600.) | (Hour, v) , Second -> (Second, v *. 3600.) | (Hour, v) , Hour -> (Hour, v) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, val_), to_unit with | (Foot, v) , Foot -> (Foot, v) | (Foot, v) , Meter -> (Meter, v *. 0.3048) | (Foot, v) , Mile -> (Mile, v /. 5280.) | (Meter, v) , Foot -> (Foot, v /. 0.3048) | (Meter, v) , Meter -> (Meter, v) | (M... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (((d,t),v),(to_d,to_t)) = ((from_unit, val_), to_unit) in (to_d,to_t),snd (convert_dist (d,v) (to_d)) /. snd(convert_time (t,1.) (to_t)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (a,((b_dist,b_time),b_val)) = (a,(b_unit, b_val)) in (b_dist,b_time), snd(convert_speed (a) (b_unit)) +. b_val ;; |
let passes_da_vinci t = 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 else false in check [t] ;; |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if (cur_num > max_num) then cur_el else max_el | h :: r -> if h = cur_el then let cur_num = cur_num + 1 in if cur_num > max_num then aux r (cur_el, cur_num) (cur_el, cur_num) else aux r (cur_e... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Error: list is empty." | h :: [] -> failwith "Error: list has only one element." | h :: r -> let list_nohead = r in let list_notail = List.rev (List.tl (List.rev l)) in let newlist = List.combine list_notail list_nohead in mode newlist ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (Hour, (val_ /. 3600.)) | (Second, Second) -> (Second, val_) | (Hour, Second) -> (Second, (val_ *. 3600.)) | (Hour, Hour) -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Foot) -> (Foot, val_) | (Foot, Meter) -> (Meter, val_ *. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Meter) -> (Meter, val_) | (Meter, Mile)... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let new_dis = convert_dist (fst(from_unit), val_) (fst(to_unit)) in let new_time = convert_time (snd(from_unit), 1.) (snd(to_unit)) in (to_unit, (snd(new_dis)) /. (snd(new_time))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let first_speed = convert_speed (a) b_unit in (b_unit, (snd(first_speed)) +. b_val) ;; |
let passes_da_vinci (t : tree) : bool = let rec helper_get_child_sum l (sum : float) : float = match l with | [] -> sum | Leaf :: tf -> helper_get_child_sum tf sum | Branch (width, _) :: tf -> helper_get_child_sum tf (sum +. width**2.) in let rec helper_through_nodes l : bool = match l with | [] -> true | Leaf :: rest_... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l,(cur_el, cur_num),(max_el, max_num) with | ([],_,_) -> max_el | (hd::tl,(_,0),(_,0)) -> aux tl (hd,1) (hd,1) | (hd::tl,(a,_),(b,_)) when hd=a && a=b -> aux tl (hd, cur_num+1) (max_el, max_num+1) | (hd::tl,... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l<2 then failwith "List too small." else let l1=header l in let l2=List.rev l in let l3=header l2 in let l4=List.rev l3 in let l5=List.combine l4 l1 in mode l5 ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Second,Hour) -> (Hour,val_ /. 3600.) | (Second,Second) -> (Second,val_) | (Hour,Second) -> (Second,val_ *. 3600.) | (Hour,Hour) -> (Hour,val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit,to_unit) with | (Foot,Meter) -> (Meter,val_ *. 0.3048) | (Foot,Mile) -> (Mile,val_ /. 5280.) | (Foot,Foot) -> (Foot,val_) | (Meter,Foot) -> (Foot,val_ /. 0.3048) | (Meter,Mile) -> (Mile,val_ /. 1609.344) | (Meter,Meter) ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let first_arg=fst(to_unit) in let second_arg=snd(to_unit) in (to_unit,snd(convert_time (second_arg,snd(convert_dist (fst(from_unit),val_) first_arg)) (snd(from_unit)))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let l1=convert_speed a (b_unit) in (b_unit, b_val+.snd(l1)) ;; |
let passes_da_vinci t = help_check [t] ;; |
let mode (l: 'a list) : 'a = let rec aux ((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 hd = cur_el then aux (cur_el, (cur_num + 1)) (max_el, max_num) tl else if cur_num > max_num then aux (hd, 1) (cur_el, cur_num) tl else aux... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Invalid input" | _::tl2 -> let l2 = tl2 in let l_rev = List.rev l in match l_rev with | [] -> failwith "Invalid input" | _::tl1 -> let l2_rev = tl1 in let l1 = List.rev l2_rev in let l3 = List.combine l1 l2 in mode l3 ;; |
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 to_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 (from_unit, val_) else match (from_unit, to_unit) with | (Meter, Meter) -> (Meter, val_) | (Mile, Mile) -> (Mile, val_) | (Foot, Foot) -> (Foot, val_) | (Mile, Foot) -> (Foot, val_ *. 5280.) | (Foot, Mile) -> ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then (from_unit, val_) else match (from_unit, to_unit) with | ((y1,x1), (y2, x2)) -> let distanceConvert = match convert_dist (y1, 1.) y2 with | (time_unit, val_) -> val_ in let timeConvert = match convert_time ... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (speed_unit,val_) = convert_speed a b_unit in (b_unit, (val_ +. b_val)) ;; |
let passes_da_vinci t = let rec sum_ l = match l with | [] -> 0. | Leaf::tl -> sum_ tl | Branch (width, subtree)::tl -> sum_ tl +. width ** 2. in let rec check l = match l with | [] -> true | Leaf::tl -> check tl | Branch (width, subtree)::tl -> if not ((check subtree) && ((sum_ subtree) <= (width ** 2.))) then false 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 | [] -> if cur_num > max_num then cur_el else max_el | hd::tl -> let next_el = hd in if cur_el = next_el then aux tl (next_el, (cur_num + 1)) (max_el, max_num) else if cur_num > max_num then aux tl (ne... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = List.tl l in let l2 = List.rev (List.tl (List.rev l)) in mode (List.combine l2 l1) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) 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, val_) 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, v... |
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 (_,val1) = convert_dist (d1, 1.0) d2 in let (_,val2) = convert_time (t1, 1.0) t2 in to_unit, val_ *. (val1 /. val2) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let converted_first_value = convert_speed a b_unit in let (_,a_val) = converted_first_value in b_unit, (a_val +. b_val) ;; |
let passes_da_vinci t = let rec checker l = let rec sum l acc = match l with [] -> acc | x :: xs -> (match x with Leaf -> sum xs acc | Branch (width, subtree) -> sum xs (acc +. width**2.0)) in let branch_checker width subtree = (width ** 2.0) >= (sum subtree 0.0) in match l with [] -> true | Leaf :: tl -> checker tl | ... |
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 (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 x... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "List does not have enough elements" | x :: xs -> if xs = [] then failwith "List does not have enough elements" else let (_ :: no_head) = (List.rev l) in mode (List.combine (List.rev no_head) (xs)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Hour, Hour | Second, Second -> (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 ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit, to_unit with | (Meter, Second), (Meter, Second) | (Meter, Hour), (Meter, Hour) -> (to_unit, val_) | (Foot, Second), (Foot, Second) | (Foot, Hour), (Foot, Hour) -> (to_unit, val_) | (Mile, Second), (Mile, Second) | (Mi... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = match fst(a), b_unit with | (Meter, Second), (Meter, Second) | (Meter, Hour), (Meter, Hour) -> (b_unit, snd(a) +. b_val) | (Foot, Second), (Foot, Second) | (Foot, Hour), (Foot, Hour) -> (b_unit, snd(a) +. b_val) | (Mile, Seco... |
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. ) <= (wi... |
let mode (l: 'a list) : 'a = let l= List.sort compare l in let rec aux (l: 'a list) (cur_element: 'a) (cur_num: int) (max_elem: 'a) (max_num: int) (cur_index: int): 'a= if cur_index<0 && cur_num>=max_num then cur_element else if cur_index<0 && cur_num<max_num then max_elem else if cur_element= (List.nth l cur_index) th... |
let pair_mode (l: 'a list) : 'a * 'a = if(List.length l <=2) then failwith "someErrorMsg" else let l1=List.tl l and l2=remove_last(l) in let l3=List.combine l2 l1 in mode l3 ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if(to_unit=from_unit) then to_unit, val_ else match to_unit with | Hour -> Hour,((val_) /.3600.) | Second-> Second ,((val_) *.3600.) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if(to_unit=from_unit) then to_unit, val_ else match from_unit with | Foot -> (match to_unit with |Meter-> Meter, val_*.0.3048 |_-> Mile,val_/.5280.) |Meter-> (match to_unit with |Foot->Foot,val_/.0.3048 |_-> Mile,val_/.1609.344) |Mile-> ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ctime=snd(from_unit) and cdistance=(fst(from_unit)) and t_time=snd(to_unit) and t_dist=fst(to_unit) in let dist=convert_dist (cdistance,val_) t_dist and time=convert_time(ctime ,val_) t_time in (fst(dist),fst(time)), snd(dist)/.(s... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let equal_unit=convert_speed a b_unit in b_unit ,snd(equal_unit)+.b_val ;; |
let passes_da_vinci t = if (t = Leaf) then true else 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 else false in check [t] ;; |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | h :: t -> if h <> cur_el then aux t (h, 1) (max_el, max_num) else if cur_num == max_num + 1 then aux t (h, cur_num + 1) (cur_el, max_num + 1) else aux t (h, cur_num+1) (max_el, max_num) | [] -> max_... |
let pair_mode (l: 'a list) = let newList = List.tl l in let otherList = List.rev l in let otherLists = List.tl otherList in let finalList = List.rev otherLists in let combinedLists = List.combine finalList newList in mode combinedLists ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let k = [from_unit; to_unit] in match k with | [Second; Hour] -> (Hour, val_ /. 3600.) | [Hour; Second] -> (Second, val_ *. 3600.) | [Hour; Hour] -> (Hour, val_) | [Second; Second] -> (Second,val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let k = [from_unit; to_unit] in match k with | [Foot; Meter] -> (Meter, val_ *. 0.3048) | [Meter; Foot] -> (Foot, val_ /. 0.3048) | [Foot; Mile] -> (Mile, val_ /. 5280.) | [Mile; Foot] -> (Foot, val_ *. 5280.) | [Meter; Mile] -> (Mile, (... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (a, b) = from_unit in let (c, d) = to_unit in let (e, f) = convert_dist (a, val_) c in let (g, h) = convert_time (b, 1.) d in ((c, d), f /. h) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (a, b) = speed_unit in let timeReal = convert_time time b in let (k, theTime) = timeReal in (a, speed_val *. theTime) ;; let rec passes_da_vinci t = if t = Leaf then true else let Branch(a, b) = t in let square = a *. a in let r... |
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 :: rest -> if (compare e cur_el) == 0 then if cur_num + 1 > max_num then aux rest (cur_el, cur_num+1) (cur_el, cur_num+1) else aux rest (cur_el, cur_num+1) (max_el, max_num) else if... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> notimplemented () | _ :: [] -> notimplemented () | _ :: rest -> let not_last = List.rev (List.tl (List.rev l)) in mode (List.combine not_last rest) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (match to_unit with | Second -> (Second, val_) | Hour -> (Hour, (val_ /. 3600.))) | Hour -> (match to_unit with | Second -> (Second, (val_ *. 3600.)) | Hour -> (Hour, val_)) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with | Foot -> (match to_unit with | Foot -> (Foot, val_) | Meter -> (Meter, val_ *. 0.3048) | Mile -> (Mile, val_ /. 5280.)) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Meter -> (Meter, val_) | Mile... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (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, (snd (convert_time time (snd speed_unit))) *. speed_val) ;; let rec passes_da_vinci t = let sum_of_squares l = List.fold_left (+.) 0. (List.map (fun a -> a *. a) l) in let get_width b = match b with | Branch (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 | [] -> max_el | e :: rest -> if (compare e cur_el) == 0 then if cur_num + 1 > max_num then aux rest (cur_el, cur_num+1) (cur_el, cur_num+1) else aux rest (cur_el, cur_num+1) (max_el, max_num) else if... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> notimplemented () | _ :: [] -> notimplemented () | _ :: rest -> let not_last = List.rev (List.tl (List.rev l)) in mode (List.combine not_last rest) ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.