text stringlengths 0 601k |
|---|
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (Hour, val_ /. 3600.) | (Hour, Second) -> (Second, val_ *. 3600.) | (Second, Second) -> (Second, val_) | (Hour, Hour) -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (Meter, val_ *. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mile) -> (Mile, (val_ /. 0.3048) /. 5280.) | (Mile, Foot) -> (Foot, va... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let val_1 = convert_dist ((fst from_unit), val_) (fst to_unit) in let val_2 = convert_time ((snd from_unit), (1. /. (snd val_1))) (snd to_unit) in to_unit, (1. /. (snd val_2)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_converted = convert_speed a b_unit in let total_val = (snd a_converted) +. b_val in b_unit, total_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 not((check subtree) && ((sum_ subtree 0.) <= (... |
let mode (l: 'a list) : 'a = match l with |[] -> failwith "Input is invalid" |_ -> let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with |[] -> if cur_num > max_num then cur_el else max_el |hd :: tl -> if hd = cur_el then if (cur_num + 1) > max_num then aux tl (hd, cur_num + 1) (hd,... |
let pair_mode (l: 'a list) : 'a * 'a = if (List.length l) < 2 then failwith "Invalid input" else let l1_hd :: l1_tl = l in let l2_hd :: l2_tl = List.rev l in let l2_tl = List.rev l2_tl in let bi_gram_l = List.combine l2_tl l1_tl in mode bi_gram_l ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match (from_unit, to_unit) with | (Second, Hour) -> (Hour, val_ /. 3600.) | (Hour, Second) -> (Second, val_ *. 3600.) | (Second, Second) -> (Second, val_) | (Hour, Hour) -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match (from_unit, to_unit) with | (Foot, Meter) -> (Meter, val_ *. 0.3048) | (Foot, Mile) -> (Mile, val_ /. 5280.) | (Meter, Foot) -> (Foot, val_ /. 0.3048) | (Meter, Mile) -> (Mile, (val_ /. 0.3048) /. 5280.) | (Mile, Foot) -> (Foot, va... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let val_1 = convert_dist ((fst from_unit), val_) (fst to_unit) in let val_2 = convert_time ((snd from_unit), (1. /. (snd val_1))) (snd to_unit) in to_unit, (1. /. (snd val_2)) ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let a_converted = convert_speed a b_unit in let total_val = (snd a_converted) +. b_val in b_unit, total_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 not((check subtree) && ((sum_ subtree 0.) <= (... |
let mode (l: 'a list) : 'a = let gfe l = match l with |x::xs -> x,xs |_ -> failwith "invalid input" in let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = if l = [] && max_num < cur_num then cur_el, cur_num else if l = [] then max_el, max_num else if cur_num > max_num then let (a,b) = gfe l in... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l = 1 then failwith "invalid input" else if List.length l = 0 then failwith "invalid input" else let l1 = List.tl l and lrev = List.rev l in let l2rev = List.tl lrev in let l2 = List.rev l2rev in let lcomplete = List.combine l2 l1 in mode lcomplete ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with |Hour -> (match to_unit with |Second -> Second, (val_*.3600.) |Hour -> Hour,(val_)) |Second -> (match to_unit with |Second -> Second, (val_) |Hour -> Hour, (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 -> 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 -> Mile, ((val_/.... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (a,b) = from_unit and (c,d) = to_unit in let (e,f) = convert_dist (a,val_) c in let (g,h) = convert_time (b,1.) d in to_unit, f/.h ;; |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let (x,y) = a in let (m,n) = convert_speed (x,y) b_unit in b_unit, (n+.b_val) ;; |
let passes_da_vinci t = let rec sumsquare l acc = match l with |[] -> acc |Leaf :: tl -> sumsquare tl acc |Branch (w,sub) :: tl -> sumsquare tl (acc +. (w*.w)) in let rec treerec y = match y with |[] -> true |Leaf :: tl -> treerec tl |Branch (w,sub) :: tl -> if not ((treerec sub) && ((sumsquare sub 0.) <= (w*.w))) then... |
let mode (l: 'a list) : 'a = if List.length l < 1 then failwith "This list is empty" else let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = if cur_num > max_num then aux l (cur_el, cur_num) (cur_el, cur_num) else match l with | [] -> max_el | hd::tl -> let head = hd in if head = cur_el then ... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "This list is too short" else let front = List.rev ( List.tl (List.rev l)) in let back = List.tl l in let pairs = List.combine front back in mode 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.)) |(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)) |(Foot, Mile) -> (Mile, (val_ /. 5280.)) |(Meter, Foot) -> (Foot, (val_ /. 0.3048)) |(Meter, Mile) -> (Mile, (val_ /. (0.3048 *. 5280.))) |(Mile, Foot) -> (Foot,... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let dist = convert_dist ((fst from_unit), val_) (fst to_unit) in let time = convert_time ((snd to_unit), (snd dist)) (snd from_unit) in let speed = (to_unit, (snd time)) in speed ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let time_conv = convert_time time (snd speed_unit) in let dist = ((fst speed_unit), (speed_val *. (snd time_conv))) in dist ;; let rec passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: sub -> sum_ sub acc |... |
let mode (l: 'a list) : 'a = match l with | [] -> failwith "Empty list" | _ -> let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | head::sublist -> aux sublist (head, if head = cur_el then cur_num + 1 else 1) (if cur_num + 1 > max_num then (cur_el, cur_num + 1) el... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "Not enough items" else let rec pair_list sublist new_list = if List.length sublist <= 1 then new_list else let rest = function | [] -> [] | _::s -> s in pair_list (rest sublist) (List.append new_list [List.hd sublist, List.hd (rest sublist)]) i... |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then failwith "Cannot have negative time" else match (from_unit, val_) with | (Second, s_val) -> (match to_unit with | Second -> (Second, s_val) | Hour -> (Hour, s_val /. 3600.)) | (Hour, h_val) -> (match to_unit with | Seco... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if val_ < 0. then failwith "Cannot have negative distance" else match (from_unit, val_) with | (Foot, f_val) -> (match to_unit with | Foot -> (Foot, f_val) | Meter -> (Meter, f_val *. 0.3048) | Mile -> (Mile, f_val /. 5280.)) | (Meter, m... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then failwith "Cannot have negative speed" else let (((d_unit,s_unit),val_),(do_unit,so_unit)) = ((from_unit, val_), to_unit) in let (_,(du,d_val),(su,s_val)) = (do_unit, (convert_dist (d_unit, val_) do_unit), (convert_ti... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if snd a < 0. || b_val < 0. then failwith "Cannot have negative speeds" else (b_unit, b_val +. snd (convert_speed a b_unit)) ;; |
let passes_da_vinci t = let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch (width, subtree) :: tl -> width *. width +. sum_ subtree acc +. sum_ tl acc in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if (check subtree) && (sum_ su... |
let mode (l: 'a list) : 'a = match l with | [] -> failwith "Empty list" | _ -> let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> max_el | head::sublist -> aux sublist (head, if head = cur_el then cur_num + 1 else 1) (if head = cur_el && cur_num + 1 > max_num then (cur_el... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "Not enough items" else let rec pair_list sublist new_list = if List.length sublist <= 1 then new_list else let rest = function | [] -> [] | _::s -> s in pair_list (rest sublist) (List.append new_list [List.hd sublist, List.hd (rest sublist)]) i... |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if val_ < 0. then failwith "Cannot have negative time" else match (from_unit, val_) with | (Second, s_val) -> (match to_unit with | Second -> (Second, s_val) | Hour -> (Hour, s_val /. 3600.)) | (Hour, h_val) -> (match to_unit with | Seco... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = if val_ < 0. then failwith "Cannot have negative distance" else match (from_unit, val_) with | (Foot, f_val) -> (match to_unit with | Foot -> (Foot, f_val) | Meter -> (Meter, f_val *. 0.3048) | Mile -> (Mile, f_val /. 5280.)) | (Meter, m... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if val_ < 0. then failwith "Cannot have negative speed" else let (((d_unit,s_unit),val_),(do_unit,so_unit)) = ((from_unit, val_), to_unit) in let (_,(du,d_val),(su,s_val)) = (do_unit, (convert_dist (d_unit, val_) do_unit), (convert_ti... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if snd a < 0. || b_val < 0. then failwith "Cannot have negative speeds" else (b_unit, b_val +. snd (convert_speed a b_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 +. width *. width) in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> ((check subtree) && (sum_ subtree 0. <= (width *. widt... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = notimplemented () in notimplemented () ;; |
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 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 == Mile then Mile, val_ /. 5280. else if to_unit == Meter then Meter, val_ *. 0.3048 else Foot, val_ | Mile -> if to_unit == Foot then Foot, val_ *. 5280. else if to_unit == Meter then Meter, val_ ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let f1 = fst from_unit in let f2 = snd from_unit in let t1 = fst to_unit in let t2 = snd to_unit in if (f1 != t1) && (f2 != t2) then let n1 = snd (convert_dist (f1, val_) t1) in (t1, t2), snd (convert_time (t2, n1) f2) else if (f1 == ... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let tUnit = fst time in let tVal = snd time in let sDist = fst speed_unit in let sTime = snd speed_unit in if tUnit != sTime then let newTime = snd (convert_time (time) sTime) in let totDist = newTime *. speed_val in sDist, totDist ... |
let head l = match l with |[] -> failwith "Empty List"| h::t -> h let tail l= match l with | [] -> failwith "Empty List"| h::t -> 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 | [] -> max_el | h::t -> if (h = cur_el && cur_num+1 > max_num) then aux t (h, cur_num+1) (h,cur_num+1) else if h = cur_el then aux t (h,cur_num+1) (max_el,max_num) else... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "List too small, space cowboy" else if l = [] then failwith "The list is empty, space cowboy" else let l1 = tail l in let l2 = List.rev (tail (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, to_unit with | Hour,Second -> (Second,val_ *. 3600.) | Second,Hour -> (Hour, val_ /. 3600.) | Second, Second -> (Second, val_) | 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) | Meter, Mile -> (Mile, val_ /. 0.3048 /. 5280.) | Mile, Meter -> (Meter, val_ *. (5280. *. 0.3048)) | Meter, Foot -> (Foot, val_ /. 0.3048) | Foot, Mile -> (Mile, val... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = match from_unit, to_unit with | (a,b), (x,y) when x = a && b = y -> ((x,y),val_) | (a,b), (x,y) when x = a -> ((x,y), snd (convert_time (y,val_) b)) | (a,b), (x,y) when y = b -> ((x,y), snd (convert_dist (a,val_) x)) | (a,b), (x,y) ->... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = (fst speed_unit, speed_val *. snd (convert_time (fst time, snd time) (snd speed_unit))) ;; let rec sum_ l acc = match l with | [] -> acc | Leaf :: tl -> sum_ tl acc | Branch(w,st) :: tl -> sum_ tl (acc +. w**2.) let rec passes_da_vi... |
let mode (l: 'a list) : 'a = let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match (List.sort compare l) with | [] -> max_el | x :: xs -> if x = max_el then aux xs ( x, cur_num+1) (x, max_num+1) else ( if x <> cur_el then aux xs (x, 1) (max_el, max_num) else ( if cur_num+1 > max_num then a... |
let pair_mode (l: 'a list) : 'a * 'a = mode ( let rec new_list l (cum: ('a * 'a) list) = match l with | x :: y :: xs -> new_list (y :: xs) (cum @ ([x,y])) | _ -> cum in match l with | x :: y :: xs -> new_list (y :: xs) ([x,y]) | _ -> notimplemented () ) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = if fst(from_unit, val_) = Second then (if to_unit = Second then (Second,val_) else (Hour, val_ /. 3600.) ) else (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 fst(from_unit, val_) with |Foot -> ( match to_unit with |Foot ->(Foot,val_) |Meter ->(Meter, val_ *. 0.3048) |Mile -> (Mile, val_ /. 5280.)) |Meter -> ( match to_unit with |Meter -> (Meter, val_) |Foot ->(Foot, val_ /.0.3048) |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 ( let converted_dist = convert_dist (fst(from_unit), val_) (fst(to_unit)) in let converted_time = convert_time (snd(from_unit), 1./.snd(converted_dist)) (snd(to_unit)) in (to_unit, 1.... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = if fst(a) = b_unit then ((b_unit), snd(a) +. b_val) else let converted_a = convert_speed (a) b_unit in ((b_unit), snd(converted_a ) +. b_val) ;; |
let passes_da_vinci t = match t with |Leaf-> true |_-> let rec check l node acc = match l with | [] -> true | Leaf :: tl -> check tl node acc | Branch (width, subtree) :: tl -> if acc+.(width**2.) <= node ** 2. && (check subtree width 0.) then check tl node (acc+.(width**2.)) else false in let Branch (width,subtree) = ... |
let mode (l: 'a list) : 'a = if l = [] then failwith "Undefined input." else let rec aux l ((cur_el, cur_num) : 'a * int) ((max_el, max_num) : 'a * int) = match l with | [] -> if cur_num > max_num then cur_el else max_el | head :: rest -> if head = cur_el then aux (rest) (cur_el, cur_num + 1) (max_el, max_num) else if ... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "Undefined input." else let rec aux (curr_index: int) (pair_list: ('a*'a) list) = let next_index = curr_index + 1 in if next_index >= List.length l then mode pair_list else aux next_index (List.append pair_list [(List.nth l curr_index, List.nth 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) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048) | Meter, Mile -> (Mile, val_ /. 1609.344) | Mile, Foot -> (Foot, val_ *. 5280.) | Mile, ... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let converted_distance = convert_dist ((fst from_unit), val_) (fst to_unit) in let converted_time = convert_time ((snd from_unit), 1.) (snd to_unit) in (to_unit, (snd converted_distance) /. (snd converted_time)) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let (_, converted_time) = convert_time time (snd speed_unit) in ((fst speed_unit),speed_val *. converted_time) ;; let sum_of_squares (child_tree : tree list): float = let rec visit_child (subtree: tree list) (sum : float) = match su... |
let mode (l: 'a list) : 'a = match l with | [] -> failwith "List is empty!" | _ :: list -> 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 let up_num = cur_num+1 in if up_num > max_num then le... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l < 2 then failwith "List does not contain enough elements!" else match l with | [] -> failwith "List is empty!" | _ :: list -> let dummy1 = l in let l1 = List.tl dummy1 in let dummy2 = l in let l2_rev = List.rev dummy2 in let l2_rev = List.tl l2_rev in let l2 = Lis... |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = let unit = fst(from_unit, val_) in let value = snd(from_unit,val_) in match to_unit with | Second -> if unit = Hour then let convert = value *.3600.0 in (Second, convert) else (unit, value) | Hour -> if unit = Second then let convert = v... |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = let unit = fst(from_unit, val_) in let value = snd(from_unit,val_) in if from_unit = to_unit then (unit, value) else match from_unit with | Foot -> if to_unit = Meter then let convert = value *. 0.3048 in (Meter, convert) else let conver... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let unit = fst(from_unit, val_) in let in_dist = fst(unit) in let in_time = snd (unit) in let out_dist = fst(to_unit) in let out_time = snd (to_unit) in let value = snd(from_unit,val_) in let convert1 = convert_time (in_time, 1.) out_... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let out_unit = b_unit in let out_val = b_val in let in_unit = fst(a) in let in_val = snd(a) in let a_speed = convert_speed(in_unit, in_val) b_unit in let a_val = snd(a_speed) in let final_val = a_val+.out_val in (out_unit, fi... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speed_dist = fst(speed_unit) in let time_unit = fst(time) in let convert = convert_speed(speed_unit, speed_val) (speed_dist, time_unit) in;; |
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 (sum_ subtree 0. > (width*.width) || 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 | [] -> 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) in let sor... |
let pair_mode (l: 'a list) : 'a * 'a = let rec bigram newList = match newList with |x1 :: x2 :: xs -> (x1,x2)::(bigram (x2::xs)) | _ -> [] in mode (bigram 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.0) | (Hour,Second) -> (Second, val_*.3600.0) | _ -> (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) | (Foot,Mile) -> (Mile, val_/.5280.0) | (Meter,Foot) -> (Foot, val_ /. 0.3048) | (Meter,Mile) -> (Mile, val_/.5280.0/.0.3048) | (Mile,Meter) -> (Meter, val_ *.5280.... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = let (dis_from,time_from) = from_unit in let (dis_to,time_to) = to_unit in let updated_dist_value = snd (convert_dist (dis_from, val_) dis_to) in let updated_time_value = snd (convert_time (time_to, updated_dist_value) time_from) in (t... |
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 = match t with | Leaf -> true | Branch (width,children) -> let rec sum_of_childs children = (match children with | [] -> 0. | x :... |
let error () = failwith "List is empty.";; |
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) els... |
let pair_mode (l: 'a list) : 'a * 'a = let rec aux old_l new_l prev = match old_l with | [] -> new_l | x :: xs -> aux xs (insert_at_end new_l (prev, x)) x in match l with | [] -> notimplemented () | x :: xs -> mode (aux xs [] x) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit with | Second -> (if to_unit = Second then (Second, val_) else if to_unit = Hour then (Hour, val_ /. 3600.) else notimplemented()) | Hour -> (if to_unit = Second then (Second, val_ *. 3600.) else if to_unit = Hour then (H... |
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 if to_unit = Mile then (to_unit, val_ /. 5280.) else notimplemented()) | Meter -> (if to_unit = Foot then ... |
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 ((fst distance, fst time), (snd distance) /. (snd time) ) ;; |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let time_unit = fst time in let time_val = snd time in let traveled_time = convert_time (time_unit, time_val) (snd speed_unit) in (fst speed_unit, speed_val *. snd traveled_time) ;; let rec sum_of_squares list sum = match list with ... |
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD... |
let add_speed (a : speed_unit value) ((b_unit, b_val) : speed_unit value) : speed_unit value = let aUnit = fst(a) in let aNumber = snd(a) in let aInBUnits = convert_speed(aUnit, aNumber) (b_unit) in let aPlusBNumber = snd(aInBUnits) +. b_val in (b_unit, aPlusBNumber) ;; |
let passes_da_vinci t = let acc = 0. in let rec check l = match l with | [] -> true | Leaf :: tl -> check tl | Branch (width, subtree) :: tl -> if ((check subtree) && ((squaredSumSubtrees acc subtree) <= (width *. width))) then check tl else false in check [t] ;; |
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max... |
let pair_mode (l: 'a list) : 'a * 'a = if List.length l <= 1 then failwith "The list is too small and does not contain any pairs!" else let l1 = List.tl (l) in let l2 = List.rev (List.tl (List.rev(l))) in let allTuples = List.combine l2 l1 in mode (allTuples) ;; |
let convert_time ((from_unit, val_) : time_unit value) to_unit : time_unit value = match from_unit, to_unit with | Second, Hour -> (Hour, val_ /. 3600.) | Hour, Second -> (Second, val_ *. 3600.) | Second, Second -> (Second, val_) | Hour, Hour -> (Hour, val_) ;; |
let convert_dist ((from_unit, val_) : dist_unit value) to_unit : dist_unit value = match from_unit, to_unit with | Foot, Foot -> (Foot, val_) | Meter, Meter -> (Meter, val_) | Mile, Mile -> (Mile, val_) | Foot, Meter -> (Meter, val_ *. 0.3048) | Foot, Mile -> (Mile, val_ /. 5280.) | Meter, Foot -> (Foot, val_ /. 0.3048... |
let convert_speed ((from_unit, val_) : speed_unit value) to_unit : speed_unit value = if from_unit = to_unit then ((fst(from_unit), snd(to_unit)) , val_) else let inputDistUnit = fst(from_unit) in let inputTimeUnit = snd(from_unit) in let outputDistUnit = fst(to_unit) in let outputTimeUnit = snd(to_unit) in let outputD... |
let dist_traveled time ((speed_unit, speed_val) : speed_unit value) : dist_unit value = let speedUnitDist = fst(speed_unit) in let speedUnitTime = snd(speed_unit) in let givenTimeUnit = fst(time) in let givenTimeNumber = snd(time) in let givenTimeInSpeedTimeUnits = convert_time(givenTimeUnit, givenTimeNumber) speedUnit... |
let mode (l: 'a list) : 'a = if l == [] then failwith "Invalid input." else 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 if (cur_num = max_num) && (compare cur_el max_el < 0) then cur_el else max... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.