text stringlengths 0 601k |
|---|
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with (Foot, Meter) -> (Meter, val_ *. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Mile) -> (Mile, val_ /. 0.3048 /. 5280.) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Mile, Meter) -> (Meter, val_... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((fd, ft), (td, tt)) = (from_unit, to_unit) in (to_unit, get_val (convert_dist (fd, get_val (convert_time (tt, val_) ft)) td)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, b_val +. get_val (convert_speed a b_unit)) ;; |
let passes_da_vinci t = let rec test root queue = match (test_ss root, queue) with (false, _) -> false | (true, []) -> true | (true, a :: l) -> test a (l @ get_children a) in test t (get_children t) ;; |
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 | [] -> (if cur_num > max_num then cur_el else max_el) | hd::tl -> (if cur_el = hd && max_num>=cur_num then aux tl (cur_el, cur_num + 1)(max_el, max_num) else (if cur_el... |
let pair_mode (l: 'a list) : 'a * 'a = let l_hd = List.rev (List.tl (List.rev l)) in let l_tl = List.tl l in let comb_list = List.combine l_hd l_tl in if (List.length l > 1) then mode(comb_list) else failwith "Cannot determine pair mode of list that is less than two elements long.";; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> Hour, val_ *. (1./.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 = match from_unit, to_unit with | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> Mile, val_ *. (1. /. 5280.) | Meter, Foot -> Foot, val_ *. (1. /. 0.3048) | Meter, Mile -> Mile, val_ *. ((1. /. 0.3048) *. (1. /. 5280.)) | Mile, Foo... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let to_distance = fst(to_unit) in let to_time = snd(to_unit) in let x = snd(convert_dist (fst(from_unit), 1.) to_distance) in let y = snd(convert_time (snd(from_unit), 1.) to_time) in to_unit, val_*.(x /. y) ;; |
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_total tail sum : float = match tail with | [] -> sum +. 0. | Leaf :: tl -> sum_total tl (sum +. 0.) | Branch (width, subtree) :: tl -> sum_total tl (sum +. (width *. width)) in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> (if ((c... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | x :: xs -> if x = cur_el then aux xs (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux xs (x, 1) (cur_el, cur_num) else ... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "The list must be bigger given the nature of the function." else let (_::xs) = l in let (_::xy) = List.rev l in let xy = List.rev xy in let pairs = List.combine xy xs in mode pairs ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let y = 3600. in match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. y) | Hour, Second -> (Second, val_ *. y) | _ -> from_unit, val_ ;; |
let convert_dist (from_unit, val_ : dist_unit value) to_unit : dist_unit value = let x = 0.3048 in let y = 5280. in let z = x *. y in let wanted_val = match (from_unit, to_unit) with | Foot, Meter -> val_ *. x | Foot, Mile -> val_ /. y | Meter, Mile -> val_ /. z | Meter, Foot -> val_ /. x | Mile, Meter -> val_ *. z | M... |
let convert_speed (from_unit, val_ : speed_unit value) to_unit : speed_unit value = let (_, convert_dist_val) = convert_dist (fst from_unit, val_) (fst to_unit) in let (_, factor) = convert_time (snd from_unit, 1.) (snd to_unit) in (to_unit, convert_dist_val /. factor);; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let x = convert_time time (snd speed_unit) in (fst speed_unit, snd x *. speed_val) ;; let rec passes_da_vinci t = let square_width t = match t with | Leaf -> 0. | Branch (width, _) -> width *. width in match t with | Leaf -> true | ... |
let invalid_input () = failwith "Not a valid input.";; |
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 cur_el x) = 0) 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 = match l with | [] -> invalid_input () | x::xs -> let l1 = xs in let l2 = List.rev (pair_mode_helper (List.rev l)) in let consec_pair_list = List.combine l2 l1 in mode consec_pair_list ;; let wrong_unit () = failwith "Not a valid unit.";; |
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_) | _ -> wrong_unit ()) | Hour -> (match to_unit with | Hour -> (Hour, val_) | Second -> (Second, val_ *. 3600.) | _ -> wrong_u... |
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.) | _ -> wrong_unit ()) | Meter -> (match to_unit with | Foot -> (Foot, val_ /. 0.3048) | Meter ->... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let converted_distance = convert_dist ((fst from_unit), 1.) (fst to_unit) in let converted_time = convert_time ((snd from_unit), 1.) (snd to_unit) in let (_, dist_val) = converted_distance in let (_, time_val) = converted_time in ( ((... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let converted_speed = convert_speed a b_unit in (b_unit, (snd converted_speed) +. b_val) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl (acc +. 0.) | Branch (width, _) :: tl -> sum_ tl (acc +. width ** 2.) in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (width, subtree) :: tl -> ((check subtree) && (sum_ subtree 0.) <= width ** 2.)... |
let mode (l: 'a list) : 'a = let sorted_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 | [] -> if (cur_num > max_num) then cur_el else max_el | x::t -> if x = cur_el then aux t (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux... |
let pair_mode (l: 'a list) : 'a * 'a = let rec pair l acc = match l with | [] -> acc | _::[] -> acc | a::(b::_ as t) -> pair t ((a,b)::acc) in mode (pair l []) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with |Second, Second -> Second, val_ |Hour, Hour -> Hour, val_ |Second, Hour -> Hour, (val_ /. 3600.) |Hour, Second -> Second, (val_ *. 3600.) ;; |
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.) |Mile, Mile -> Mile, val_ |Mile, Foot -> Foot, (val_ *. 5280.) |Mile, Meter -> Meter, (val_ *.1609.344) |... |
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 (dist, dist_val) = convert_dist (from_dist, val_) to_dist in let (time, time_val) = convert_time (from_time, 1.) to_time in (dist, time), (dist_val /. time_va... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (dist_unit, to_time) = speed_unit in let (from_time, from_time_val) = time in let (_ , time_val) = convert_time (from_time, from_time_val) to_time in dist_unit, (speed_val *. time_val) ;; let sum_of_squares l = let rec sum l acc... |
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) (pos: int) = if pos = List.length l then max_el else if cur_el = List.nth l pos then aux l (cur_el, (cur_num + 1)) (max_el, max_num) (pos + 1) else if cur_num > max_num then aux l ((Li... |
let pair_mode (l: 'a list) : 'a * 'a = let l1 = List.tl l in let l3 = List.rev l in let l2 = List.tl l3 in let l4 = List.combine l1 l2 in mode l4 ;; |
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 |Hour -> to_unit, val_ |Second -> to_unit, (val_ *. 3600.) ) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with |Foot -> (match to_unit with |Foot -> to_unit, val_ |Meter -> to_unit, (val_ *. 0.3048) |Mile -> to_unit, (val_ /. 5280.) ) |Meter -> (match to_unit with |Foot -> to_unit, (val_ /. 0.3048) |Meter -> to_unit, val_ |Mi... |
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 conv_dist = convert_dist (from_dist, val_) to_dist in let conv_time = convert_time (to_time, snd(conv_dist... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_speed_unit = fst a in let a_value = snd a in let a_conv = convert_speed (a_speed_unit, a_value) b_unit in let speed_sum = snd a_conv +. b_val in b_unit, speed_sum ;; |
let passes_da_vinci t = let branches_sum l = match l with |[] -> 0. |Leaf::tl -> 0. |Branch(width, subtree) :: tl -> (width *. width) in let sum_ l = match l with |[] -> 0. |Leaf::tl -> 0. |Branch(width, subtree)::tl -> branches_sum subtree in let rec check l = match l with | [] -> true | Leaf :: tl -> true | Branch (w... |
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 then(if cur_num=0 then aux tl (cur_el, 1) (cur_el, 1) else if cur_num=max_num then aux tl (cur_el, cur_num+1) (cur_el, cur_num+1) else aux tl (cur_el, cur_num+... |
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Undefined Input" | [x] -> failwith "Undefined Input" | hd1::tl1 -> let tl2 = (List.tl (List.rev l)) in mode (List.combine (List.rev tl2) tl1) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Second, Second) -> (Second,val_) | (Hour, Hour) -> (Hour,val_) | (Second, Hour) -> (Hour,(val_ /. 3600.)) | (Hour, Second) -> (Second,(val_ *. 3600.)) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Foot) -> (Foot, val_) | (Meter, Meter) -> (Meter,val_) | (Mile, Mile) -> (Mile,val_) | (Foot, Meter) -> (Meter,(0.3048 *. val_)) | (Meter, Foot) -> (Foot,(val_ /. 0.3048)) | (Foot, Mile) -> (Mile,... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (du1,du2,tu1,tu2) = (fst(from_unit),fst(to_unit),snd(from_unit),snd(to_unit)) in let val_t = snd(convert_time (tu2,val_) tu1) in let val_td = snd(convert_dist (du1, val_t) du2) in ((du2,tu2),val_td) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a2_val = snd(convert_speed a b_unit) in let rtn_val = a2_val +. b_val in (b_unit,rtn_val) ;; |
let passes_da_vinci t = let rec helper tree_list acc = match tree_list with | [] -> acc | hd::tl -> match hd with | Leaf -> helper tl acc | Branch (f, _) -> (helper tl (acc +. f *. f)) in let rec check tree_list = match tree_list with | [] -> true | Leaf::tl -> check tl | Branch (width, subtree) :: tl -> let rst = widt... |
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 if cur_num=max_num && cur_el < max_el then cur_el else max_el |x::xs -> if x==cur_el then if (cur_num+1>max_num) then aux xs (cur_el, cur_num+1) (cur_el, cur_... |
let pair_mode (l: 'a list) : 'a * 'a = let rec aux l1 (l1: 'a list) (l2: 'a list)= l2=List.tl l l1=[] ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = notimplemented () ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = notimplemented () ;; |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = notimplemented () ;; |
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 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 if cur_num=max_num && cur_el < max_el then cur_el else max_el |x::xs -> if x=cur_el then if (cur_num+1>max_num) then aux xs (cur_el, cur_num+1) (cur_el, cur_n... |
let pair_mode (l: 'a list) : 'a * 'a = match l with |[] -> failwith "Empty List!" |[x] ->failwith "At least 2 entries!" |_ ->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 with |Second -> if to_unit=Second then (to_unit, val_) else (to_unit,val_/.3600.) |Hour -> if to_unit=Second then (to_unit, val_*.3600.) else (to_unit,val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit with |Foot -> if to_unit =Foot then (to_unit, val_) else if to_unit =Meter then (to_unit, val_*.0.3048) else (to_unit, val_/.5280.) |Meter -> if to_unit =Foot then (to_unit, val_/.0.3048) else if to_unit =Meter then (to_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ftu= snd from_unit in let fdu= fst from_unit in let ttu=snd to_unit in let tdu=fst to_unit in let val_1= snd (convert_dist (fdu, val_ ) tdu) in (to_unit,snd (convert_time(ttu, val_1) ftu)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let spval =b_val +.snd (convert_speed (a) b_unit) in (b_unit, spval) ;; |
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 width*.width >= sum_ subtree 0. then let a = check subtree in if a the... |
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 cur_el = h then aux t (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux t (h, 1) (cur_el, cur_num) else aux t... |
let pair_mode (l: 'a list) : 'a * 'a = let rec pairs el list = match list with | [] -> [] | [i] -> (el, i)::[] | h::t -> (el, h)::(pairs h t) in mode (pairs (List.hd l) (List.tl l)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, val_) with | (Second, _) -> ( match to_unit with | Hour -> (Hour, val_ /. 3600.) | _ -> (Second, val_) ) | (Hour, _) -> ( match to_unit with | Second -> (Second, val_ *. 3600.) | _ -> (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 | Meter -> (Meter, (val_ *. 0.3048)) | Mile -> (Mile, (val_ /. 5280.)) | _ -> (Foot, val_) ) | (Meter, _) -> ( match to_unit with | Foot -> (Foot, (val_ /. 0.3048)) | Mile ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let fst (x, y) = x in let scd (x, y) = y in match (from_unit, val_) with | ((Foot, t), val_) -> (match fst to_unit with | Meter -> if (scd to_unit) = t then ((Meter, t), scd (convert_dist (Foot, val_) Meter)) else ((Meter, (scd to_uni... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let fst (x, y) = x in let scd (x, y) = y in if scd speed_unit = fst time then (fst speed_unit, speed_val *. (scd time)) else (fst speed_unit, speed_val *. scd (convert_time time (scd speed_unit))) ;; let rec passes_da_vinci t = noti... |
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 :: tl -> if h = cur_el then aux tl (cur_el, cur_num+1) (max_el, max_num) else if cur_num > max_num then aux tl (h, 1) (cur_el, cur_num) else au... |
let pair_mode (l: 'a list) : 'a * 'a = let rec generate_bigram (bi_l : (('a * 'a) list)) (l : 'a list) (element : 'a)= match l with | [] -> bi_l | h :: tl -> generate_bigram ((element,h) :: bi_l) tl h in if (List.length l) < 2 then failwith "list too short" else mode (generate_bigram [] (List.tl l) (List.hd l)) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> if to_unit = Hour then (to_unit, val_ /. 3600.) else (from_unit, val_) | Hour -> if to_unit = Second then (to_unit, val_ *. 3600.) else (from_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 | Foot -> (from_unit, val_) | Meter -> (to_unit, val_ *. 0.3048) | Mile -> (to_unit, val_ /. 5280.)) | Meter -> (match to_unit with | Foot -> (to_unit, val_ /. 0.3048) | Meter -> (from_u... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = (to_unit, (get_nd_el (convert_dist (get_st_el from_unit, val_) (get_st_el to_unit))) /. (get_nd_el (convert_time (get_nd_el from_unit, 1.0) (get_nd_el to_unit)))) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = (b_unit, get_nd_el (convert_speed a b_unit) +. b_val) ;; |
let passes_da_vinci t = match t with | Leaf -> true | Branch (width, subtree) -> if width *. width >= cal_sos subtree then true && (search_tree subtree) else false ;; |
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 ... |
let pair_mode (l: 'a list) : 'a * 'a = if (List.length l) = 2 then ((List.nth l 0),(List.nth l 1)) else let rec pair_list l (cur_list: ('a * 'a) list) = match l with | x1 :: x2 :: xs -> pair_list (List.cons x2 xs) (List.cons (x1,x2) cur_list) | _ -> mode cur_list in pair_list l [] ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> (match from_unit with | Second -> (to_unit, val_) | Hour -> (to_unit, (val_ *. 3600.)) ) | Hour -> (match from_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 to_unit with | Foot -> (match from_unit with | Foot -> (to_unit, val_) | Meter -> (to_unit, (val_ /. 0.3048)) | Mile -> (to_unit, (val_ *. 5280.)) ) | Meter -> (match from_unit with | Foot -> (to_unit, (val_ *. 0.3048)) | Meter -> ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let val_ = second_el (convert_dist ((first_el from_unit),val_) (first_el to_unit)) in let val_ = second_el (convert_time ((second_el to_unit),val_) (second_el from_unit)) in (to_unit, val_) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let val_ = b_val +. (second_el (convert_speed a b_unit)) in (b_unit, val_) ;; |
let passes_da_vinci t = match t with | Leaf -> true | Branch (width,subtree) -> if (width ** 2.) < (branch_sum t) then false else let rec check_all tree_list = match tree_list with | [] -> true | x :: xs -> ( match x with | Leaf -> check_all xs | Branch (width, _) -> if (width ** 2.) < (branch_sum x) then false else 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 |[] -> 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 max_num >= cur_num then aux tl (hd, 1) (max_el, max_num) else... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "more elements required" else let l1 = List.tl l in let l2 = List.rev (List.tl (List.rev l)) in let tupleList = List.combine l2 l1 in mode tupleList ;; |
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 distance = convert_dist (fst from_unit, val_) (fst to_unit) in let time = convert_time (snd from_unit, 1.) (snd to_unit) in (to_unit, snd distance /. snd time) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let timeInSpeedUnit = convert_time time (snd speed_unit) in (fst speed_unit, speed_val *. snd timeInSpeedUnit) ;; let rec passes_da_vinci t = let rec sum l acc = match l with | [] -> acc | Leaf :: tl -> sum tl acc | Branch (width, _... |
let mode (l: 'a list) : 'a = let rec aux lst ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match lst with | [] -> if cur_num > max_num then cur_el else max_el | element :: lst -> if cur_el = element then aux lst (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux lst (element, 1... |
let pair_mode (l: 'a list) : 'a * 'a = let rec run (lst: 'a list) (maintain: ('a * 'a) list) (last: 'a) = match lst with | [] -> mode maintain | element :: lst -> run lst ((last, element) :: maintain) element in match l with | [] -> failwith "Undefined input." | element :: lst -> run lst ([]) element ;; |
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_) | Mil... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist: dist_unit value) = convert_dist ((fst from_unit), 1.) (fst to_unit) in let (time: time_unit value) = convert_time ((snd from_unit), 1.) (snd to_unit) in (((fst to_unit), (snd from_unit)), val_ *. (snd dist) /. (snd time)) ;... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (speed: speed_unit value) = convert_speed ((fst (fst a), snd (fst a)), snd a) b_unit in (b_unit, snd speed +. b_val) ;; |
let passes_da_vinci t = let rec sum (lst: tree list) (add: float): float = match lst with | Branch (diameter, _) :: next -> sum next (diameter *. diameter +. add) | Leaf :: next -> sum next add | _ -> add in let rec check_branch (branch: tree list): bool = (match branch with | Branch (diameter, lst) :: next -> if ((dia... |
let mode (l: 'a list) : 'a = let rec aux lst ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match lst with | [] -> if cur_num > max_num then cur_el else max_el | element :: lst -> if cur_el = element then aux lst (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux lst (element, 1... |
let pair_mode (l: 'a list) : 'a * 'a = let rec run (lst: 'a list) (maintain: ('a * 'a) list) (last: 'a) = match lst with | [] -> mode maintain | element :: lst -> run lst ((last, element) :: maintain) element in match l with | [] -> failwith "Undefined input." | one :: [] -> failwith "Undefined input." | element :: lst... |
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_) | Mil... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dist: dist_unit value) = convert_dist ((fst from_unit), 1.) (fst to_unit) in let (time: time_unit value) = convert_time ((snd from_unit), 1.) (snd to_unit) in (((fst to_unit), (snd from_unit)), val_ *. (snd dist) /. (snd time)) ;... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (speed: speed_unit value) = convert_speed ((fst (fst a), snd (fst a)), snd a) b_unit in (b_unit, snd speed +. b_val) ;; |
let passes_da_vinci t = let rec sum (lst: tree list) (add: float): float = match lst with | Branch (diameter, _) :: next -> sum next (diameter *. diameter +. add) | Leaf :: next -> sum next add | _ -> add in let rec check_branch (branch: tree list): bool = (match branch with | Branch (diameter, lst) :: next -> if ((dia... |
let mode (l: 'a list) : 'a = let rec aux lst ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match lst with | [] -> if cur_num > max_num then cur_el else max_el | element :: lst -> if cur_el = element then aux lst (cur_el, cur_num + 1) (max_el, max_num) else if cur_num > max_num then aux lst (element, 1... |
let pair_mode (l: 'a list) : 'a * 'a = let rec run (lst: 'a list) (maintain: ('a * 'a) list) (last: 'a) = match lst with | [] -> mode maintain | element :: lst -> run lst ((last, element) :: maintain) element in match l with | [] -> failwith "Undefined input." | one :: [] -> failwith "Input size too small." | element :... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.