text
stringlengths
0
601k
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (_, value) = (convert_speed a b_unit) in (b_unit, value +. b_val) ;;
let passes_da_vinci t = let rec sum_of_squares l acc = match l with | [] -> acc | Leaf :: tl -> sum_of_squares tl acc | Branch (width, subtree) :: tl -> sum_of_squares tl (acc +. (width ** 2.)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if not (check subtr...
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 (hd,cur_num+1) (max_el, max_num) else if cur_num > max_num then aux tl (hd,1) (cur_el, cur_num) else aux tl (hd,...
let pair_mode (l: 'a list) : 'a * 'a = let l1 = List.tl l in let l2 = List.rev (List.tl (List.rev l)) in let l3 = List.combine l2 l1 in mode l3 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match(from_unit,to_unit) with | Second,Hour -> (to_unit, (val_/.3600.)) | Hour,Second -> (to_unit, (val_*.3600.)) |_->(to_unit, val_);;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match(from_unit,to_unit) with |Foot,Meter -> (to_unit, (val_*.0.3048)) |Foot,Mile -> (to_unit, (val_/.5280.)) |Meter,Foot-> (to_unit, (val_/.0.3048)) |Meter, Mile-> (to_unit, (val_/.1609.344)) |Mile,Foot-> (to_unit, (val_*.5280.)) |Mile,...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((dist1,time1),(dist2,time2)) = (from_unit, to_unit) in ((dist2,time2), (second_element (convert_time (time2, (second_element (convert_dist (dist1, val_) dist2))) time1))) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let b = second_element(speed_unit) in let timeval = convert_time (time) b in (first_element(speed_unit), speed_val*.second_element(timeval)) ;; let rec passes_da_vinci t = let rec sum_ l acc= match l with |[] -> acc |Branch (width,_...
let invalidInput () = failwith "Invalid input type";;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num>max_num then cur_el else max_el | hd::tl -> if hd=cur_el then aux (tl) (cur_el,cur_num+1) (max_el, max_num) else (if cur_num>max_num then aux (tl) (hd,1) (cur_el, cur_num) else aux ...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] | [_] -> invalidInput() | f::_ -> let l1=match l with | e1::r ->r | o->o in let l2=match List.rev l with | e1::r->List.rev r | o->o in let l3=List.combine l2 l1 in mode(l3); ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit,to_unit) with | (Second, Hour) -> (to_unit,val_ /. 3600.) | (Hour, Second) -> (to_unit,val_ *. 3600.) | (_,_) -> (to_unit,val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit,to_unit) with | (Foot, Meter) -> (to_unit,val_ *. 0.3048) | (Foot, Mile) -> (to_unit,val_ /. 5280.) | (Meter, Foot) -> (to_unit,val_ /. 0.3048) | (Meter, Mile) -> ( to_unit, (val_ /. 0.3048) /.5280. ) | (Mile, Foot) -> (...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (a,b,c,d) = ((fst from_unit), (snd from_unit), (fst to_unit), (snd to_unit)) in ((to_unit), snd(convert_dist (a, val_) c ) /. snd(convert_time (b,1.) d ) );;
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (a,b) = (a, b_unit) in (b, snd(convert_speed (fst(a),snd(a)) b) +. b_val) ;;
let passes_da_vinci (t:tree) : bool= let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, st) :: tl -> if not (check st && ((sum_ st 0.) <= width*.width) ) then false else check tl in check [t];;
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | x :: xs -> if x = cur_el then if cur_num + 1 > max_num then aux xs (x, cur_num + 1) (x, cur_num + 1) else aux xs (x, cur_num + 1) (max_el, max_num) else aux xs (x, 1) (max_el, max_num...
let pair_mode (l: 'a list) : 'a * 'a = let rem (l: 'a list) : 'a list = match l with | [] -> failwith "Invalid input" | x :: xs -> if xs == [] then failwith "Invalid input" else xs in let l1 = rem l in let l2 = List.rev (rem (List.rev 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 = let from: time_unit = fst (from_unit, val_) in let valu: float = snd (from_unit, val_) in if from = to_unit then (to_unit, valu) else match from with | Hour -> (Second, (valu *. 3600.0)) | Second -> (Hour, (valu /. 3600.0)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let from: dist_unit = fst (from_unit, val_) in let valu: float = snd (from_unit, val_) in match from with | Foot -> if to_unit = Foot then (to_unit, valu) else if to_unit = Meter then (to_unit, valu *. 0.3048) else (to_unit, valu /. 5280...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let from: speed_unit = fst (from_unit, val_) in let valu: float = snd (from_unit, val_) in let dist = convert_dist ((fst from), valu) (fst to_unit) in let time = convert_time ((snd from), 1.0) (snd to_unit) in (to_unit, (snd dist) /. ...
let dist_traveled (time: time_unit value) ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed: speed_unit value = (speed_unit, speed_val) in let con_time: time_unit value = convert_time time (snd (fst (speed))) in let dist: float = (snd speed) *. (snd con_time) in ((fst (fst (speed))), dist) ;; l...
let mode (l: 'a list) : 'a = let rec loop maxelt maxcount elt count = function | [] -> if count > maxcount then elt else maxelt | x::xs -> if elt = x then loop maxelt maxcount elt (count + 1) xs else if count > maxcount then loop elt count x 1 xs else loop maxelt maxcount x 1 xs in match List.sort compare l with | x::x...
let pair_mode (l: 'a list) : 'a * 'a = let rec pair l= match l with | a:: b:: xs -> (a, b) :: pair (b:: xs) | _::[] -> pair [] |[] -> [] in mode (pair 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 == 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, to_unit) with |(Foot, Meter) -> to_unit, val_ *. 0.3048 |(Meter, Foot) -> to_unit, val_ /. 0.3048 |(Foot, Mile) -> to_unit, val_ /.5280. |(Mile, Foot) -> to_unit, val_ *.5...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match (from_unit, to_unit) with |((a, b),(c, d)) -> let (e, f) = convert_dist(a, val_) c in let (g, h) = convert_time(b, 1.) d in to_unit, f /.h ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = match speed_unit with |(a, b) -> match time with |(c, d) -> let (e, f) = convert_time(c, d) b in a, speed_val *.f ;; let rec passes_da_vinci t = notimplemented (); ;;
let get_value xy = let (x,y) = xy in y;; let get_x xy = let (x,y) = xy in x;;
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 == 0 then aux xs (x, 1) (x, 1) else if cur_el <> x && cur_num <= max_num then aux xs (x, 1) (max_el, max_num) else if cur_e...
let pair_mode (l: 'a list) : 'a * 'a = let bruh = pair_mode_helper l [] in mode (bruh) ;;
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) | Meter, Foot -> (to_unit, val_ /. 0.3048) | Meter, Mile -> (to_unit, val_ /. 0.3048 /. 5280.) | Mile, Meter -> (to_unit, val_ *. 5280. *. 0.3048) | Foot, Mile -> (...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let ((a,b),(c,d)) = (from_unit, to_unit) in ((c,d), (get_value (convert_time (d, (get_value (convert_dist (a, val_) c))) b))) ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (get_x speed_unit, (get_value (convert_time time (get_value speed_unit))) *. speed_val) ;; let rec passes_da_vinci t = let get_weight t : float = match t with | Leaf -> 0. | Branch (x,y) -> x in let get_list t : tree list = match 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...
let pair_mode (l: 'a list) : 'a * 'a = let rec pair_list (l: 'a list) (last_el: 'a) plist = match l with | [] -> failwith "Empty list" | x :: [] -> (last_el, x) :: plist | x :: xs -> (pair_list xs x ((last_el, x) :: plist)) in match l with | [] -> failwith "Cannot compute pair for empty list" | x :: [] -> (x, x) | x ::...
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 | Second -> (Hour, (val_ /. 3600.)) | Hour -> (Second, (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 -> (match to_unit with | Meter -> (Meter, (val_ *. 0.3048)) | Mile -> (Mile, (val_ /. 5280.))) | Meter -> (match to_unit with | Foot -> (Foot, (val_ /. 0.3048...
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 (_, new_speed) = convert_dist (from_dist, val_) to_dist in let (_, factor) = convert_time (from_time, 1.) to_time in (to_unit, new_speed /. factor) ;;
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 (b_unit, b_val +. new_speed1) ;;
let passes_da_vinci (t: tree) = let rec all_leaf_thiccness_v2 tree_lst curr_list: (float list) = match tree_lst with | [] -> curr_list | Leaf :: xs -> all_leaf_thiccness_v2 xs curr_list | Branch (x, new_tree) :: xs -> (all_leaf_thiccness_v2 xs (x::curr_list)) in let rec sum_of_square lst sum = match lst with | [] -> su...
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 + 1 > max_num then aux tl (cur_el, cur_num + 1) (cur_el, cur_num + 1) else aux tl (cur_el, cur_num + 1) (max_el, max_num)) else aux tl (h...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "List must have at least 2 elements" | _ :: [] -> failwith "List must have at least 2 elements" | _ :: tl -> mode (List.combine (List.rev @@ List.tl @@ List.rev l) tl) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let new_val = match (from_unit, to_unit) with | (Second, Hour) -> val_ /. 3600. | (Hour, Second) -> val_ *. 3600. | _ -> val_ in (to_unit, new_val) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let new_val = match (from_unit, to_unit) with | (Foot, Meter) -> val_ *. 0.3048 | (Foot, Mile) -> val_ /. 5280. | (Meter, Foot) -> val_ /. 0.3048 | (Meter, Mile) -> (val_ /. 0.3048) /. 5280. | (Mile, Foot) -> val_ *. 5280. | (Mile, Meter...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let new_val = let ((from_dist_unit,from_time_unit), (to_dist_unit,to_time_unit)) = (from_unit, to_unit) in (convert_dist (from_dist_unit, val_) to_dist_unit, convert_time (from_time_unit, 1.) to_time_unit) in let ((_,dist_val),(_,time...
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 sum_of_squares_tr (trees : tree list) (acc : float) : float = match trees with | [] -> acc | hd :: tl -> let recurse = match hd with | Leaf -> sum_of...
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 | [] -> failwith "Undefined input." | [_] -> max_el | h :: t -> if h <> (List.nth t 0) then aux t (List.nth t 0, 1) (max_el, max_num) else let cur_num' = cur_num + 1 in let max_el' = if cur_num' > max...
let pair_mode (l: 'a list) : 'a * 'a = let rec recurse l acclist= match l with | [] -> mode (List.rev (acclist)) | [_] -> mode (List.rev (acclist)) | h :: t :: [] -> mode (List.rev ((h, t) :: acclist)) | h :: h2 :: t -> recurse (h2 :: t) ((h, h2) :: acclist) in if List.length l = 0 || List.length l = 1 then failwith "U...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then failwith "Time values cannot be negative." else match (from_unit, val_) with | (Hour, _) -> (match to_unit with | Hour -> (Hour, val_) | Second -> (Second, val_ *. 3600.0)) | (Second, _) -> (match to_unit with | Hour ->...
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if val_ < 0. then failwith "Distance values cannot be negative." else match (from_unit, val_) with | (Foot, _) -> (match to_unit with | Foot -> (Foot, val_) | Mile -> (Mile, (val_ /. 5280.0)) | Meter -> (Meter, (val_ *. 0.3048))) | (Mile...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then failwith "Speed values cannot be negative." else let distance' = (convert_dist (fst from_unit, val_) (fst to_unit)) in let time' = (convert_time (snd from_unit, 1.0) (snd to_unit)) in let timeMult = 1.0 /. (snd time'...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let speed' = convert_speed a b_unit in (b_unit, (snd speed') +. b_val);;
let passes_da_vinci t = let rec ttf (t: tree) = match t with | Leaf -> true | Branch (width, subtrees) -> if (width ** 2.) >= findSubtreeSum subtrees then ctf subtrees else false and ctf subtreeList = match subtreeList with | [] -> true | h :: t -> ttf h && ctf t in ttf t;;
let mode (l: 'a list) : 'a = let rec aux (l:'a list) ((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 :: body -> begin if head = cur_el then aux body (cur_el, cur_num + 1) (max_el, max_num) else ( if cur_num > max_num then aux body ...
let pair_mode (l: 'a list) : 'a * 'a = match l with | [] -> failwith "Undefined Input" | [x] -> failwith "Invalid Input" | _ -> begin let list1 = remove_first_el l in let list2 = List.rev l in let list3 = remove_first_el list2 in let list4 = List.rev list3 in let list_tuples = List.combine list4 list1 in mode list_tupl...
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match to_unit with | Second -> begin match fst(from_unit, val_) with | Second -> (Second, val_) | Hour -> (Second, val_ *. 3600.) end | Hour -> begin match fst(from_unit, val_) with | Hour -> (Hour, val_) | Second -> (Hour, val_ /. 3600....
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match to_unit with | Foot -> begin match fst(from_unit, val_) with | Foot -> (Foot, val_) | Meter -> (Foot, val_ /. 0.3048) | Mile -> (Foot, val_ *. 5280.) end | Meter -> begin match fst(from_unit, val_) with | Meter -> (Meter, val_) | F...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match fst(to_unit) with | Foot -> begin match snd(to_unit) with | Second -> begin match fst(from_unit) with | Foot -> begin match snd(from_unit) with | Second -> (to_unit, val_) | Hour -> (to_unit, val_ /. 3600.) end | Meter -> begin ...
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 l (acc: float) = match l with | [] -> acc | Leaf :: tl -> sum_l tl acc | Branch (width, _) :: tl -> sum_l tl (width**2. +. acc) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ( not (check subtree) || sum_l 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 | hd::tl -> if cur_el = hd then aux tl (cur_el,cur_num+1) (max_el,max_num) else if cur_num > max_num then aux tl (hd,1) (cur_el,cur_num) else aux t...
let pair_mode (l: 'a list) : ('a *'a) = if List.length l < 2 then failwith "Invalid list length." else let (_::new_list1) = l in let (_::new_list2) = List.rev l in let new_list2 = List.rev new_list2 in let new_list3 = List.combine new_list2 new_list1 in mode new_list3 ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (fst(from_unit,val_),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 (fst(from_unit,val_),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_ /. 0.3048 /. 5...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let from_unit_time = snd(fst(from_unit,val_))in let to_unit_time = snd(to_unit) in let time_conversion = convert_time (from_unit_time, 1.) to_unit_time in let time = snd(time_conversion) in let from_unit_dist = fst(fst(from_unit,val_)...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let unit_for_dist = fst(fst(speed_unit,speed_val)) in let unit_for_time = snd(fst(speed_unit,speed_val)) in let convert_given_time = convert_time time unit_for_time in let magnitude_of_speed = snd(speed_unit, speed_val) in (unit_for...
let notimplemented () = failwith "This function is not yet implemented." type dist_unit = Foot | Meter | Mile type time_unit = Second | Hour type speed_unit = dist_unit * time_unit type 'a value = 'a * float type tree = Branch of float * tree list | Leaf let tree_example = Branch (5., [ Branch (3., [Leaf; Leaf; Leaf]);...
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 hd = List.hd l in let tl = List.tl l in let f (pre, acc) cur = (cur, (pre, cur)::acc) in let pair_list = List.rev (snd (List.fold_left f (hd, []) tl)) in mode pair_list ;;
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 = match from_unit, to_unit with | Mile, Meter -> Meter, val_ *. 5280. *. 0.3048 | Mile, Foot -> Foot, val_ *. 5280. | Meter, Mile -> Mile, val_ /. (5280. *. 0.3048) | Meter, Foot -> Foot, val_ /. 0.3048 | Foot, Mile -> Mile, val_ /. 5280. ...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let fdu, ftu = from_unit in let tdu, ttu = to_unit in let _, dist = convert_dist (fdu, 1.) tdu in let _, time = convert_time (ttu, 1.) ftu in (tdu, ttu), val_ *. time *. dist ;;
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let du, tu = speed_unit in let _, t = convert_time time tu in du, speed_val *. t ;; let rec passes_da_vinci t = let map_all f = List.fold_left (fun r e -> r && f e) true in let rec sum_tree = function | [] -> 0. | Leaf::ts -> sum_tr...
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 = if (List.length l) >= 2 then let l1 = List.tl l in let l2 = List.rev l in let l3 = List.tl l2 in let l4 = List.rev l3 in let l5 = List.combine l4 l1 in mode l5 else failwith "Undefined input." ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let init_unit = fst(from_unit, val_) in let value = snd(from_unit, val_) in if init_unit = to_unit then (to_unit, value) else match init_unit with | Hour -> (Second, (value *. 3600.)) | Second -> (Hour, (value /. 3600.)) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let init_unit = fst(from_unit, val_) in let value = snd(from_unit, val_) in match init_unit, to_unit with | Foot, Foot -> (Foot, value) | Meter, Meter -> (Meter, value) | Mile, Mile -> (Mile, value) | Foot, Meter -> (Meter, (value *. 0.3...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let from_unit_dist = fst(from_unit) in let from_unit_time = snd(from_unit) in let from_value = snd(from_unit, val_) in let to_unit_dist = fst(to_unit) in let to_unit_time = snd(to_unit) in if (fst(from_unit, val_)) = to_unit then (to_...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_unit = fst(a) in let a_value = snd(a) in let unit_b = fst(b_unit, b_val) in let value_b = snd(b_unit, b_val) in if a_unit = unit_b then (a_unit, a_value +. value_b) else let result = convert_speed (a_unit, a_value) unit...
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch (width, _) :: tl -> sum_ tl (acc + int_of_float(width *. width)) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((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) : 'a = match l with | [] -> max_el | x :: xs -> if (compare x cur_el) = 0 then if cur_num + 1 > max_num then aux xs (cur_el, (cur_num + 1)) (cur_el, (cur_num + 1)) else aux xs (cur_el, (cur_num + 1)) (max_el, max_nu...
let pair_mode (l: 'a list) : 'a * 'a = 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 = let secs_in_hr = 3600. in match (from_unit, to_unit) with | (Second, Hour) -> (Hour, val_ /. secs_in_hr) | (Hour, Second) -> (Second, val_ *. secs_in_hr) | _ -> (from_unit, val_) ;;
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let fts_in_mi = 5280. in let mts_in_ft = 0.3048 in match (from_unit, to_unit) with | (Foot, Mile) -> (Mile, val_ /. fts_in_mi) | (Mile, Foot) -> (Foot, val_ *. fts_in_mi) | (Foot, Meter) -> (Meter, val_ *. mts_in_ft) | (Meter, Foot) -> (...
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, dist_value) = convert_dist (from_dist_unit, val_) to_dist_unit in let (time_unit, time_value) = convert_time (from_time_...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (dist_unit, time_unit) = speed_unit in let (_, time_val) = convert_time time time_unit in (dist_unit, speed_val *. time_val) ;; let tree1 = Branch (5., [ Branch (3., [Leaf; Leaf; Leaf]); Leaf; Branch (4., []) ]) ;; let tree2 = B...
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 + 1) > max_num then aux tl (cur_el, cur_num +1) (cur_el, cur_num +1) else aux tl (cur_el, cur_num +1) (max_el, max_num) else aux tl (hd, 1) (...
let pair_mode (l: 'a list) : 'a * 'a = let rec gen_pair_list (l: 'a list) p_list = match l with | hd::[] -> p_list | hd::tl -> gen_pair_list tl ((hd, List.hd tl) :: p_list) in mode (gen_pair_list l []) ;;
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let hour_to_second = 3600. in let second_to_hour = 1. /. hour_to_second in match (from_unit, val_), to_unit with | (Second, val_), Second -> (Second, val_) | (Second, val_), Hour -> (Hour, val_ *. second_to_hour) | (Hour, val_), Hour -> ...
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let foot_to_meter = 0.3048 in let meter_to_foot = 1. /. foot_to_meter in let mile_to_foot = 5280. in let foot_to_mile = 1. /. mile_to_foot in let meter_to_mile = meter_to_foot *. foot_to_mile in let mile_to_meter = 1. /. meter_to_mile in...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (((dist_from_unit, time_from_unit), val_), (dist_to_unit, time_to_unit)) = ((from_unit, val_), to_unit) in let new_dist = convert_dist (dist_from_unit, val_) dist_to_unit in let new_time = convert_time (time_from_unit, 1.0) time_t...
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (speed_dist_unit, speed_time_unit) = speed_unit in let time = convert_time time speed_time_unit in let (_, t_val) = time in (speed_dist_unit, speed_val *. t_val) ;; let branch_width t = match t with | Leaf -> 0. | Branch(w, _) -...
let mode (l: 'a list) : 'a = let l = List.sort compare l in match l with | [] -> failwith "Input cannot be empty" | x::_ -> 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...
let pair_mode (l: 'a list) : 'a * 'a = if (List.length l) < 2 then failwith "Input must have at least 2 values" else let l = List.combine (List.rev (List.tl (List.rev l))) (List.tl l) in mode l ;;
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 = Hour then (to_unit, val_) else (to_unit, val_ *. 3600.) ;;
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 = Mile then (to_unit, val_ /. 5280.) else (to_unit, val_ *. 0.3048) | Meter -> if to_unit = Meter then (to_unit, val_) else if to_unit = Foot then (to_...
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((to_unit), val_) else if fst(from_unit) = fst(to_unit) && snd(from_unit) != snd(to_unit) then ((to_unit), snd(convert_time (snd(to_unit), val_) (snd(from_unit)))) else if fst(from_unit) != fst(to_unit) && ...
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let newspeed = convert_speed a b_unit in ((b_unit), snd(newspeed) +. b_val) ;;