text
stringlengths
0
601k
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let checkNode list node = let (n1, n2, cost) = node in if n1 = vertex then (n2,cost) :: list else list in List.fold_left checkNode [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (curr,weight) = node in if curr = b then ( (List.rev (curr :: visited), weight) ) else ( if List.mem curr visited then raise Fail else let neighbourList = neighbours g c...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (curr,weight) = node in if curr = b then (fc [curr], sc weight) else ( if List.mem curr visited then raise Fail else let neighbourList = neighbours g curr in let f...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all = find_all_paths g a b in let max = ref (-1) in let longest_path = ref ([],-1) in let rec find_max paths = match paths with | [] -> !longest_path | (p, weight)::t -> if weight >= !max then (max := weight; longest_path := (p, weigh...
let open_account (initial_pass: passwd) : bank_account = ( let user_pass = ref initial_pass in let money = ref 0 in let num_tries = ref 0 in { update_pass = (fun old_pass new_pass -> ( if old_pass = !user_pass then (user_pass := new_pass; num_tries := 0) else (num_tries := !num_tries + 1; raise wrong_pass); () )); retr...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun init edge -> match edge with | (point1, point2, weight) -> if point1 = vertex then (point2, weight) :: init else init | _ -> failwith "Not an edge") [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((name, edge_weight): 'a * weight) (visited : 'a list) : ('a list * weight) = let (p_list, p_weight) = aux_list (neighbours g name) (name :: visited) in (name::p_list, edge_weight + p_weight) and aux_list (nodes: ('a * weight) list) (vi...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((name, edge_weight): 'a * weight) (visited : 'a list) fc sc: ('a list * weight) = aux_list (neighbours g name) (name :: visited) fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc: ('a list * weight) = let non_vis...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths g a b in match all_paths with | [] -> None | _ -> Some (List.fold_left (fun (cur_list, cur_weight) (path_list, path_weight) -> if path_weight > cur_weight then (path_list, path_weight) else (cur_list, cur_we...
let open_account (initial_pass: passwd) : bank_account = let p = ref initial_pass in let balance= ref 0 in let failures = ref 0 in { update_pass = (fun oldP newP -> if !p = oldP then (p := newP; failures := 0) else (failures := !failures + 1; raise wrong_pass)); deposit = (fun pass amt -> if !failures >= 5 then raise t...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper el acc = let (edge1, edge2, w) = el in if edge1 = vertex then (edge2, w)::acc else acc in List.fold_right helper g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec get_solution (node: 'a) (visited : 'a list) : ('a list * weight) = if node = b then ([b], 0) else let remaining = List.filter(fun el -> let (v1, v2, _) = el in (not (List.mem v2 visited)) && v1 = node) g.edges in match remaining with | [] -> rai...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper (node : 'a) (visited : 'a list) fail (suc : ('a list * weight) -> ('a list * weight)) = if node = b then suc ([b], 0) else let remaining = List.filter(fun el -> let (v1, v2, w) = el in (not (List.mem v2 visited)) && v1 = node) g.edges in...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l = find_all_paths g a b in match l with | [] -> None | _ -> let l' = List.sort (fun x y -> let (_, w1) = x in let (_, w2) = y in w2 - w1) l in match l' with | [] -> None | h::_-> Some h;;
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let balance = ref 0 in let x : int ref = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if not (String.equal (!pw)(old_pass)) then (x := !x + 1; raise wrong_pass;) else ( x := 0; pw := new_pass; )); deposit = (...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let my_func = fun (v1, v2, w) r -> if v1 = vertex then (v2,w)::r else r in List.fold_right (my_func) (g.edges) ([]);;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = notimplemented () in notimplemented ();;
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented ();;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();;
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let count = ref 0 in let money = ref 0 in let check_pw pw1 = if !count >=5 then raise too_many_failures else let true_pw = !pw in if true_pw = pw1 then (count :=0) else (count := !count +1; raise wrong_pass) in let update_pass old_pw ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge = g.edges in let rec find edge vertex acc = match edge with |[] -> acc |(v1,v2,w) :: t -> if v1 = vertex then find t vertex [(v2,w)]@acc else find t vertex acc in find edge vertex [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v,w) = node in if (List.mem v visited) then raise Fail else if v = b then ([v],w) else let (l,w_total) = aux_list (neighbours g v) (v ::visited) in(v::l, w + w_total) a...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v,w) = node in if (List.mem v visited) then fc () else if v = b then sc ([v],w) else (aux_list (neighbours g v) (v ::visited) fc (fun (l,w_total) -> sc (v::l, w +...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec long l = match l with | [] -> None | [(l,w)] -> Some (l,w) | (l1,w1)::(l2,w2) ::t -> if w1>=w2 then long ((l1,w1)::t) else long ((l2,w2)::t) in long(find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let failures = ref 0 in { update_pass = ( fun input_pass new_pass : unit -> if input_pass = !pass then (pass := new_pass; failures := 0) else (failures := !failures + 1; raise wrong_pass)); retrieve = ( fun in...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f vertex edge init = let (x, y, w) = edge in if x = vertex then (y, w) :: init else init in List.fold_right (f vertex) g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (nodes: ('a * weight) list) (visited: ('a * weight) list) : (('a * weight) list) = match nodes with | [] -> raise Fail | nodes_hd :: nodes_tl -> if List.mem nodes_hd visited then raise Fail else let (hd_node, _) = nodes_hd in if hd_node...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (nodes: ('a * weight) list) (visited: ('a * weight) list) fc sc = match nodes with | [] -> fc () | nodes_hd :: nodes_tl -> if List.mem nodes_hd visited then fc () else let (hd_node, hd_weight) = nodes_hd in if hd_node = b then sc ([hd_...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented();;
let open_account (initial_pass: passwd) : bank_account = let cur_pass = ref initial_pass in let cur_balance = ref 0 in let attempts = ref 0 in { update_pass = (fun old_pass new_pass -> if (!cur_pass = old_pass) then (cur_pass := new_pass; attempts := 0;) else (attempts := !attempts + 1; raise wrong_pass)); retrieve = (...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun neighbours edge -> (let (current, dest, wt) = edge in if current = vertex then (dest, wt) :: neighbours else neighbours)) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v,w) = node in if List.mem v visited then raise Fail else if v = b then ([v],w) else let (nextA,nextWeight) = aux_list (neighbours g v) (v::visited) in (v::nextA,w+next...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v,w) = node in if List.mem v visited then fc () else if v = b then sc ([v],w) else aux_list (neighbours g v) (v::visited) fc (fun (nextA,nextWeight) -> sc (v::nex...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match List.sort (fun (_,wa) (_,wb) -> if wa > wb then +1 else if wa < wb then -1 else 0) (find_all_paths g a b) with | [] -> None | (v,w)::_ -> Some(v,w);;
let open_account (initial_pass: passwd) : bank_account = let current_balance = ref 0 in let current_password = ref initial_pass in let num_failures = ref 0 in { update_pass = (fun old_pass new_pass -> if (old_pass = !current_password) then (current_password := new_pass ; num_failures := 0;) else (num_failures := !num_f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f a (n1, n2, w) = if (n1 = vertex) then (n2, w) :: a else a in List.fold_left f [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((cur, w): 'a * weight) (visited : 'a list) final_node weight : ('a list * weight) = if (cur = final_node) then (List.rev (final_node :: visited), weight + w) else (if (not (List.mem cur visited)) then aux_list (neighbours g cur) (cur :...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (cur, w) visited fc sc final_node weight : ('a list * weight)= if (cur = final_node) then (sc final_node visited weight w) else (if (not (List.mem cur visited)) then aux_list (neighbours g cur) (cur :: visited) fc sc (weight + w) else ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max x y = if x >= y then x else y in let rec aux lst accW accL = match lst with | [] -> if accL = [] then None else Some (accL, accW) | (p, w) :: t -> let new_W = max accW w in if (new_W = accW) then aux t new_W accL else aux t new_W ...
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let tries = ref 0 in let password = ref initial_pass in { deposit = ( fun p f -> if (!tries < 5) then if (p = !password) then let () = tries := 0 in match f with | f when f < 0 -> raise negative_amount | _ -> balance := (!balance + f); else...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges l = match edges with | [] -> l | (u, v, weight) :: xs when u = vertex -> helper xs (l @ [(v, weight)]) | _ :: xs -> helper xs l in helper g.edges [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc: int) : ('a list * weight) = let (u, weight) = node in match (u, weight) with | (v1, some) when v1 = b -> (visited @ [b]), acc + some | (prev, _) when List.mem prev visited -> raise Fail | (b...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (u, weight) = node in match (u, weight) with | (v1, some) when v1 = b -> (visited @ [b], sc some) | (prev, _) when List.mem prev visited -> fc () | (bruh, moment) ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in match paths with | [] -> None | _ -> let rec find_max l (max, maxw) = match l with | [] -> (max, maxw) | (l, weight) :: tl -> if weight > maxw then find_max tl (l, weight) else find_max tl (max, maxw) i...
let open_account (initial_pass: passwd) : bank_account = let local_password = ref initial_pass in let local_bal = ref 0 in let attempts = ref 0 in { update_pass = (fun (old_password:passwd) (new_password: passwd) -> if old_password = !(local_password) then (attempts := 0 ; local_password := new_password ) else (incr at...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let folder (x: 'a*'b*'c) (y: 'd) = let (v,n,w) = x in if v = vertex then (n,w)::y else y in List.fold_right folder g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v,w) = node in let node_neighbours = (neighbours g v) in let path = if v = b then ([],0) else if not (List.mem v visited) then aux_list node_neighbours (v::visited) els...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v,w) = node in if v = b then sc ([v],w) else if not (List.mem v visited) then aux_list (neighbours g v) (v::visited) fc (fun (p,wt) -> sc (v::p, (w + wt))) else f...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();;
let open_account (initial_pass: passwd) : bank_account = let local_password = ref initial_pass in let local_bal = ref 0 in let attempts = ref 0 in { update_pass = (fun (old_password:passwd) (new_password: passwd) -> if old_password = !(local_password) then (attempts := 0 ; local_password := new_password ) else (incr at...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let folder (x: 'a*'b*'c) (y: 'd) = let (v,n,w) = x in if v = vertex then (n,w)::y else y in List.fold_right folder g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v,w) = node in let node_neighbours = (neighbours g v) in let path = if v = b then ([],0) else if not (List.mem v visited) then aux_list node_neighbours (v::visited) els...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v,w) = node in if v = b then sc ([v],w) else if not (List.mem v visited) then aux_list (neighbours g v) (v::visited) fc (fun (p,wt) -> sc (v::p, (w + wt))) else f...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max paths maxPath = match paths with |[]-> maxPath |path::tl -> let (p,w) = path in let (pM,wM) = maxPath in if w > wM then max tl path else max tl maxPath in let paths = (find_all_paths g a b) in match paths with |[]-> None |_-> ...
let open_account (initial_pass: passwd) : bank_account = let wpasscount = ref 0 in let balance = ref 0 in let cur_pass = ref initial_pass in { update_pass = (fun old_pass new_pass -> if !cur_pass = old_pass then (cur_pass := new_pass; wpasscount := 0) else (wpasscount := !wpasscount + 1;raise wrong_pass) ) ; deposit = ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let choice (t: ('a * weight) list) (tuple: 'a * 'a * weight) : ('a * weight) list = let (a,b,c) = tuple in if a = vertex then List.append t [(b,c)] else t in List.fold_left choice [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (str,w) = node in if List.mem str visited then raise Fail else( let visited1 = List.append visited [str] in if str = b then (visited1, w) else( let adding (tup : 'a * we...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (str, w) = node in if List.mem str visited then fc () else( let visited1 = List.append visited [str] in if(str = b) then (visited1, sc w) else( let neigh = neighbo...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in match paths with | [] -> None | _ -> ( let compare (c,d) (a,b) = if(b >= d) then (a,b) else (c,d) in let answer = List.fold_left compare (List.hd paths) (List.tl paths) in Some(answer) );;
let open_account (initial_pass: passwd) : bank_account = let stored_pass = ref initial_pass in let balance = ref 0 in let fail_cont = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !stored_pass then (stored_pass := new_pass; fail_cont := 0;) else (fail_cont := !fail_cont + 1 ; raise wrong_pass)) ; dep...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let neighbour_check node result= (let (checked,going_to,w) = node in if checked = vertex then ((going_to,w):: result) else result) in List.fold_right neighbour_check g.edges [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (name,weight)=node in if List.mem name visited then raise Fail else if name=b then ([name],weight) else let (path,final_weight) = (aux_list (neighbours g name) (name::vi...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (name,weight)=node in if List.mem name visited then fc () else if name=b then sc ([name],weight) else aux_list (neighbours g name ) (name::visited) fc (fun (path,n...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths g a b in let rec find_highest_num paths (high:int):int = match paths with | [] -> high | x::xl -> let (_,num)=x in if num > high then find_highest_num xl num else find_highest_num xl high in let rec find_pat...
let open_account initpass = let passwd = ref initpass in let numfailed = ref 0 in let balance = ref 0 in { update_pass = (fun entered newpass -> if entered = !passwd then begin passwd:= newpass; numfailed := 0 end else begin numfailed := !numfailed + 1; raise wrong_pass end ) ; retrieve = (fun entered wd -> if !numfail...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun x -> match x with (_,v2,w) -> (v2,w)) (List.filter (fun node -> match node with | (v1,_,_) -> v1 = vertex ) g.edges);;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (neighbors: 'b list) (visited : 'a list) (weight: int): ('a list * weight) = match neighbors with | [] -> raise Fail | head::tl -> try match head with | (dest, w) -> if not (List.exists (fun a -> a=dest) visited) then if dest = b then (...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (neighbors: 'b list) (visited : 'a list) fc sc : ('a list * weight)= match neighbors with | [] -> fc () | head::tl -> match head with | (dest, w) -> if not (List.exists (fun h -> h=dest) visited) then if dest = b then (visited @ [b], w...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();;
let open_account initpass = let passwd = ref initpass in let numfailed = ref 0 in let balance = ref 0 in { update_pass = (fun entered newpass -> if entered = !passwd then begin passwd:= newpass; numfailed := 0 end else begin numfailed := !numfailed + 1; raise wrong_pass end ) ; retrieve = (fun entered wd -> if !numfail...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun x -> let (_,v2,w) = x in (v2, w)) (List.filter (fun node -> let (v1,_,_) = node in v1 = vertex ) g.edges);;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (neighbors: 'b list) (visited : 'a list) (weight: int): ('a list * weight) = match neighbors with | [] -> raise Fail | head::tl -> try let (dest,w) = head in if not (List.exists (fun a -> a=dest) visited) then if dest = b then (visited ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight) = let (dest, w) = node in if not (List.exists (fun h -> h=dest) visited) then if dest = b then (visited @ [b], w + sc 0) else aux_list (neighbours g dest) (visited @ [d...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in let rec aux ls maxcost route = match ls with | head::tl -> let (l, c) = head in if c > maxcost then aux tl c l else aux tl maxcost route | [] -> match route with | [] -> None | _ -> Some (route, maxcost...
let open_account (initial_pass : passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let num_failures = ref 0 in let update_pass (old_pass : passwd) (new_pass : passwd) = if !password = old_pass then ( num_failures := 0; password := new_pass ) else ( num_failures := !num_failures + 1; rai...
let neighbours (g : 'a graph) (vertex : 'a) : ('a * weight) list = let f = fun vertex -> fun ls -> fun (edge : ('a * 'a * weight)) -> let (v1, v2, w) = edge in if v1 = vertex then (v2, w)::ls else ls in List.fold_left (f vertex) [] g.edges;;
let find_path (g : 'a graph) (a : 'a) (b : 'a) : ('a list * weight) = let rec aux_node (node : 'a * weight) (visited : 'a list) (cur_w : weight): ('a list * weight) = let (v, w) = node in if v = b then (visited @ [v], cur_w + w) else if List.exists ((=) v) visited then raise Fail else aux_list (neighbours g v) (visited...
let find_path' (g : 'a graph) (a : 'a) (b : 'a) : ('a list * weight) = let rec aux_node (node : 'a * weight) (visited : 'a list) fc sc (to_visit : ('a * weight) list): ('a list * weight) = match node with | (v, _) when v = b -> sc (node, visited, fc 0) | (v, _) when List.exists ((=) v) visited && to_visit = [] -> raise...
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let rec aux_node (node : 'a * weight) (visited : 'a list) (weights : weight list) (paths : ('a list * weight) list) : ('a list * weight) list = let (v, w) = node in;;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in let rec get_max_length paths max_length = match paths with | hd::tl -> let (_, length) = hd in if length > max_length then get_max_length tl length else get_max_length tl max_length | [] -> max_length i...
let open_account (initial_pass: passwd) : bank_account = let curr_pass = ref initial_pass and curr_balance = ref 0 and caution = ref 0 in { update_pass = (fun pass newPass -> if (not(pass = !curr_pass)) then begin caution := !caution + 1; raise wrong_pass end else begin curr_pass := newPass; caution := 0 end); retrieve...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = helper (List.filter (fun (x, _, _) -> vertex = x) g.edges) [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc : weight) : ('a list * weight) = match node with | (nextDoor, w) when nextDoor = b -> (List.rev visited @ [nextDoor], w + acc) | (nextDoor, w) -> if List.mem nextDoor visited then raise Fail ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (fc) (sc: ('a list * weight) -> ('a list * weight)) : ('a list * weight) = match node with | (nextDoor, w) when nextDoor = b -> sc ([nextDoor], w) | (nextDoor, w') -> if List.mem nextDoor visited...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let find l = match l with | [] -> None | x :: _ -> Some x in find (List.rev (List.sort (fun (_, w) (_, w') -> compare w w') (find_all_paths g a b))) ;;
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let failures = ref 0 in let auth_fail = fun f exc -> f := !f + 1; raise exc in let update = fun f p n_p -> f := 0; p := n_p in let dep_helper = fun f b a -> f := 0; b := !b + a in let ret_helper = fun f b a ->...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = notimplemented ();;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = notimplemented () in notimplemented ();;
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented ();;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();;
let open_account (initial_pass: passwd) : bank_account = let cur_pass = ref initial_pass in let balance = ref 0 in let failures = ref 0 in let verify pass = if (!failures >= 5) then raise too_many_failures else if (pass <> !cur_pass) then (failures := !failures + 1; raise wrong_pass) else failures := 0 in { update_pass...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let append_neighbour neighbour_list (source, dest, w) = if source = vertex then (dest, w) :: neighbour_list else neighbour_list in List.fold_left append_neighbour [] g.edges let neighbours_sum (g: 'a graph) (vertex: 'a) (acc: weight) : ('a * weight) list ...
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec visit_node (cur: 'a) (acc: weight) (visited : 'a list): ('a list * weight) = visit_neighbours (neighbours_sum g cur acc) (cur :: visited) and visit_neighbours (neighbours: ('a * weight) list) (visited: 'a list) : ('a list * weight) = match neigh...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec visit_node (cur: 'a) (visited : 'a list) fc sc : ('a list * weight)= visit_neighbours (neighbours g cur) (cur :: visited) fc sc and visit_neighbours (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = match nodes with | ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in match paths with | [] -> None | _ -> let max_weight (p1, w1) (p2, w2) = if w1 > w2 then (p1, w1) else (p2, w2) in Some (List.fold_left max_weight ([], min_int) paths);;
let security_loop p my_password my_tries = if(!my_tries >= 5) then raise too_many_failures else if(String.equal !my_password p) then my_tries := 0 else let _ = my_tries := !my_tries +1 in raise wrong_pass ;;
let open_account (initial_pass: passwd) : bank_account = let my_password= ref initial_pass in let my_balance= ref 0 in let my_tries= ref 0 in { update_pass= (fun (new_p: passwd) -> if(String.equal !my_password new_p) then (fun new_p -> my_password:= new_p) else raise wrong_pass); deposit = (fun p a-> if(a < 0) then rai...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if(not (List.find (fun vertex -> vertex) g.nodes)) then raise Fail else let rec match_edges l_edges vertex lacc = match l_edges with | [] -> [] | (v1, v2,w)::t -> match (v1, v2,w) with | (vertex, _, _) -> (v2, w)::lacc | _ -> match_edges t vertex lacc in ...
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = notimplemented () in notimplemented ();;
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented ();;