text
stringlengths
0
601k
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper (a: string) (b : string) (l: string list) (w: weight) (v: string list) (flag: bool): (string list * weight) = if flag then (l, w) else let theNeighbours = neighbours g a in match theNeighbours with | [] -> raise Fail | x::xs -> ( if (get...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = None;;
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let log_counter = ref 0 in let bl = ref 0 in { update_pass = (fun opw npw -> if opw = !pw then (log_counter:=0; pw := npw) else (log_counter := !log_counter+1; raise wrong_pass)); retrieve = (fun opw amt -> if opw = !pw then if !log_c...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get_fst (v1,_,_) = v1 in let p str tp = get_fst tp = str in let elist = List.filter (p vertex) (g.edges) in let f tp = let (_,v2,w) = tp in (v2,w) in List.map f elist ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let length = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v1,w) = node in if v1 = b then (List.rev (v1::visited), !length+w) else if (List.mem v1 visited) then (length := !length+w; raise Fail) else (leng...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let length = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight) = let (v1,w) = node in if v1 = b then sc ((visited@[v1]), !length+w) else if (List.mem v1 visited) then (length := !length+w; fc ()) else (length ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match (find_all_paths g a b) with | [] -> None | (p,w)::_ -> Some (p,w) ;;
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let amount = ref 0 in let count = ref 0 in {update_pass = (fun x y -> (if compare x !pass != 0 then (count := !count+1; raise wrong_pass) else (pass := y; count := 0))); retrieve = (fun l m -> (if !count > 4 then raise too_many_fail...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let n x y = let (a,b,c) = y in if compare a vertex == 0 then x @ [(b,c)] else x in List.fold_left n [] g.edges ;; let removeFirst (l: 'a list): ('a list)= match l with | [] -> [] | x :: xs -> xs let rec onlyFirst (l : ('a*weight) list) (m : 'a list) : 'a ...
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : ('a * weight) list): ('a list * weight) = if compare (fst(node)) b == 0 then find g node (a, 0) (List.rev (removeDouble visited [])) [fst(node)] 0 else if List.mem node visited then raise Fail else aux_lis...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : ('a*weight) list) fc sc : ('a list * weight) = if compare (fst(node)) b == 0 then sc node visited else if List.mem node visited then fc () else aux_list (neighbours g (fst(node))) (visited @ [node]) fc sc...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let n = find_all_paths g a b in match n with | [] -> None | _ -> largest n (List.nth n 0);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let failure_count = ref 0 in let balance = ref 0 in { update_pass = (fun oldpassword newpassword -> if (oldpassword = !password) then (password := newpassword; failure_count := 0) else(failure_count := !failure_count + 1;(raise ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge l (b, c,d) = if b =vertex then (c,d) :: l else l in List.fold_left edge [] g.edges;; let graph1 = {nodes = ["Victoria"; "Hull"; "Brooks"; "Surrey "]; edges = [("Hull", "Brooks", 15); ("Victoria", "Hull", 12); ("Surrey ", "Hull", 1); ("Hull", "Sur...
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 node,weight = node in let totalpath = if node = b then ([],0) else if not (List.mem node visited) then aux_list (neighbours g node) (node::visited) else raise Fail in le...
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 (node,weight) = node in if node = b then sc ([node],weight) else if not (List.mem node visited) then aux_list (neighbours g node) (node::visited) (fc) (fun (totalp...
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 password = ref initial_pass in let failure_count = ref 0 in let balance = ref 0 in { update_pass = (fun oldpassword newpassword -> if (oldpassword = !password) then (password := newpassword; failure_count := 0) else(failure_count := !failure_count + 1;(raise ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge l (b, c,d) = if b =vertex then (c,d) :: l else l in List.fold_left edge [] g.edges;; let graph1 = {nodes = ["Victoria"; "Hull"; "Brooks"; "Surrey "]; edges = [("Hull", "Brooks", 15); ("Victoria", "Hull", 12); ("Surrey ", "Hull", 1); ("Hull", "Sur...
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 node,weight = node in let totalpath = if node = b then ([],0) else if not (List.mem node visited) then aux_list (neighbours g node) (node::visited) else raise Fail in le...
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 (node,weight) = node in if node = b then sc ([node],weight) else if not (List.mem node visited) then aux_list (neighbours g node) (node::visited) (fc) (fun (totalp...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec maxpath curlist bestpath curmaxweight = match curlist with | [] -> bestpath | hd :: tl -> let (list, weight) = hd in if (weight >= curmaxweight) then (maxpath tl hd weight) else maxpath tl bestpath curmaxweight in let to_b = maxpa...
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let lock = ref false in { update_pass = (fun (pass : passwd) (new_pw : passwd) -> if not(pass = !pw) then ( if !counter >= 4 then lock := true ; counter := !counter + 1 ; raise (wrong_pass...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (e: 'a * 'a * weight) acc -> if isOutEdge vertex e then let (i,o,w) = e in (o,w)::acc else acc) g.edges [] ;; let compute_path (path: 'a list) : ('a list * weight) = let sum = ref 0 in let gPath = ref [] in let res = () List.iter (fun...
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let path = ref [(a, 0)] in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let neighbourList = neighbours g a in match neighbourList with |((node:'a), (w: weight)):: x -> let ((n:'a), (w: weight)) = List.hd x in (path := ...
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 password = ref initial_pass in let account_balance = ref 0 in let wrongattempts = ref 1 in let updatepass_fun oldpass newpass = if oldpass = !password then (password := newpass; wrongattempts := 1;) else (wrongattempts := !wrongattempts + 1; raise wrong_pass)...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find_outneighbours edges vertex acc = match edges with | [] -> acc | (v1, v2, w) :: xs -> (if v1 = vertex then find_outneighbours xs vertex ((v2, w) :: acc) else find_outneighbours xs vertex acc) in find_outneighbours g.edges 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 (x, w) = node in if List.mem x visited then raise Fail else let outneighbours = neighbours g x in let (path_nodes, total_weight) = aux_list outneighbours (x :: 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 (x, w) = node in if List.mem x visited then fc () else let outneighbours = neighbours g x in aux_list outneighbours (x :: visited) fc (fun (r1, r2) -> sc (x :: r1...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let allpaths = find_all_paths g a b in if allpaths = [] then None else let (x :: xs) = allpaths in let rec iterate_paths paths longest = match paths with | [] -> longest | y :: ys -> (let (p1, w1) = y in let (p2, w2) = longest in if w1 > ...
let open_account (initial_pass: passwd) : bank_account = let bal = ref 0 in let pass = ref initial_pass in let count = ref 0 in { update_pass = (fun oldp newp -> if oldp = !pass then ( pass := newp ; count := 0) else (count := !count + 1 ; raise wrong_pass)) ; retrieve = (fun p amt -> if !count < 5 then if p = !pass th...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f vertex e acc = let (left_v,right_v, w) = e in if left_v = vertex then (right_v,w) :: acc else acc in List.fold_right (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) : ('a list * weight) = let (n,w) = node in let newW = w in if n = b then ([b] , w) else (if List.mem n visited then raise Fail else let (x,wei) = aux_list (neighbours g n)(n :: visited) in (n :: x...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) succ fail : ('a list * weight) = let (n,w) = node in let newW = w in if n = b then succ ([b] , w) else (if List.mem n visited then fail () else let succ2 = fun (x, wei) -> succ (n :: x , newW + w...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec traverse (paths : ('a list * weight) list) = match paths with |[] -> None |[(x,wei)] -> Some (x,wei) |(x,w1):: (y, w2) :: xs -> if w1 >= w2 then traverse ((x,w1) :: xs) else traverse ((y,w2) :: xs) in traverse (find_all_paths g a ...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let failure = ref 0 in let balance = ref 0 in let failure_fun() = failure := (!failure + 1); raise wrong_pass in let update_pass (old_pass: passwd) (new_pass: passwd) = match old_pass = !password with | true -> password := new_p...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let { nodes = _; edges = e } = g in List.fold_left (helper vertex) [] e;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight : int): ('a list * weight) = let (vertex, w) = node in match List.mem vertex visited with | true -> raise Fail | false -> match vertex = b with | true -> ((visited @ [vertex]), weight + w)...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight : int) fc sc : ('a list * weight)= let (vertex, w) = node in match List.mem vertex visited with | true -> fc() | false -> match vertex = b with | true -> sc ((visited @ [vertex]), weight ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight : int) fc : ('a list * weight) list = let (vertex, w) = node in match List.mem vertex visited with | true -> fc() | false -> match vertex = b with | true -> ((visited @ [ver...
let open_account (initial_pass: passwd) : bank_account = let current_bal = ref 0 in let current_pass = ref initial_pass in let wrong_att = ref 0 in let update_pass (old_pass : passwd) (new_pass : passwd) : unit = if old_pass = !current_pass then (current_pass := new_pass; wrong_att := 0) else (incr wrong_att; raise wro...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec check_edges e_list v final = match e_list with |(a, b, weight)::tl -> if a = v then check_edges tl vertex (final@[(b,weight)]) else check_edges tl vertex final |[] -> final in check_edges g.edges vertex [] exception Fail1 of string;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper edges start finish path tot_weight = match edges with |[]-> raise Fail |(u,v,weight)::tl -> if u = start && v = finish && not (List.mem v path) then (path@[v], tot_weight + weight) else if u = start && not (List.mem v path) then try helpe...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (tot_weight : weight) fc : ('a list * weight)= if b <> fst node then aux_list (neighbours g (fst node)) visited tot_weight fc else (List.rev visited, tot_weight) and aux_list (nodes: ('a * weight...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max_len = ref 0 in let max_path = ref [] in let rec move_thru paths = match paths with | (path, weight)::tl -> if weight > !max_len then (max_len := weight; max_path := path; move_thru tl) else move_thru tl | [] -> if !max_len = 0 the...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in { update_pass = (fun old new_ -> if old = !password then (password := new_; counter := 0) else (counter := succ !counter ; raise wrong_pass)) ; retrieve = (fun pass amount -> if !cou...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun a (v0, v1, w) -> if v0 = vertex then (v1, w)::a else a) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((c, w): 'a * weight) ((v_list, v_weight): 'a list * weight) : ('a list * weight) = if c = b then (v_list@[c], w + v_weight) else if List.exists (fun e -> e = c) v_list then raise Fail else aux_list (neighbours g c) (v_list@[c], w + v_w...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, w): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if node = b then sc ([node], w) else if List.exists (fun e -> e = node) visited then fc () else aux_list (neighbours g node) (node::visited) fc (fun (next_node, n...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let lp = (find_all_paths g a b) |> List.fold_left (fun (l1, w1) (l2,w2) -> if w1 > w2 then (l1, w1) else (l2, w2)) ([], -1) in if (snd lp) != -1 then Some(lp) else None;;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = (fun password_prov new_pass -> if password_prov = !password then let _ = (attempts := 0) in password := new_pass else let _ = attempts := !attempts+1 in raise wrong_...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec list_neighbours nodes n cont = match nodes with | [] -> cont [] | (v1, v2, w) :: t -> if v1 = n then list_neighbours t n (fun f -> cont ((v2, w) :: f)) else list_neighbours t n cont in list_neighbours g.edges vertex (fun f -> f) ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) total_weight: ('a list * weight) = let (cur_node, cur_weight) = node in if(cur_node = b) then (List.rev (cur_node::visited), total_weight+cur_weight) else if List.exists ((=) cur_node) visited the...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) total_weight fc sc : ('a list * weight)= let (cur_node, cur_weight) = node in if(cur_node = b) then sc (List.rev (cur_node::visited), total_weight+cur_weight) else if List.exists ((=) cur_node) v...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let comparator (cur_list, cur_weight) max_el = match max_el with |None -> Some(cur_list, cur_weight) |Some(max_list, max_weight) -> if max_weight > cur_weight then Some(max_list, max_weight) else Some(cur_list, cur_weight) in List.fold_ri...
let open_account (initial_pass: passwd) : bank_account = let (password: passwd ref) = ref initial_pass in let (balance : int ref) = ref 0 in let (attempts : int ref) = ref 0 in let passcheck (pass: passwd) = attempts := !attempts + 1; if !password <> pass then raise wrong_pass else attempts := 0 in let failcheck = if !...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (x,y,z) -> if x = vertex then (y,z) :: acc else acc) [] 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 (x,y) = node in if b = x then ([x],y) else if not (List.exists (fun z -> x = z) visited) then let (path, weight) = aux_list (neighbours g x) (x :: visited) in (x :: path...
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 (x,y) = node in if b = x then sc ([x],y) else if not (List.exists (fun z -> x = z) visited) then aux_list (neighbours g x) (x :: visited) fc (fun (path, weight) -...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec finder paths a b = match paths with | [] -> Some (a, b) | (x,y) :: xs -> if y >= b then finder xs x y else finder xs a b in let paths = find_all_paths g a b in if paths = [] then None else finder paths [] 0 ;;
let open_account (initial_pass: passwd) : bank_account = let right_passwd = ref initial_pass in let attempts = ref 0 in let balance = ref 0 in let new_account:bank_account={ update_pass = (fun (old_one:passwd)(new_one:passwd)-> if old_one= right_passwd.contents then begin attempts:=0; right_passwd:=new_one end else beg...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges output = match edges with | [] -> output | (v1,v2,distance) :: others -> if v1=vertex then helper others ((v2,distance)::output) else helper others output in helper (g.edges) [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux visited vertices path acc = match vertices with | [] -> raise Fail | (x,weight)::rest -> if List.mem x visited then aux visited rest path acc else if x=b then ((path@[b]),acc + weight) else try aux (x::visited) rest path acc with Fail -> aux...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux visited vertices path suc = match vertices with | [] -> raise Fail | (x,weight)::rest -> if List.mem x visited then aux visited rest path suc else if x=b then ((path@[b]),suc weight) else try aux (x::visited) rest path suc with Fail -> let ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (all : ('a list * weight) list) longest weight = match all with | [] -> Some longest | (l,w)::rest -> if w >= weight then helper rest (l,w) w else helper rest longest weight in let all_paths = find_all_paths g a b in match ...
let helper x = if x>=5 then raise too_many_failures;;
let open_account (initial_pass:passwd): bank_account = let pw = ref initial_pass in let count = ref 0 in let balance = ref 0 in {update_pass=(fun old_pw new_pw -> if old_pw = !pw then (pw:= new_pw ; count := 0) else if !count >= 5 then raise wrong_pass else (count := (!count +1) ; raise wrong_pass)); deposit =(fun inpu...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper node (edge_list: ('a * 'a * weight) list) lst = match edge_list with |(v1, v2 ,w):: tl -> if v1 = node then helper node tl ((v2,w) :: lst) else helper node tl lst |[] -> lst in helper vertex g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (g: 'a graph) (nodes: ('a * weight) list) (dest: 'a) (visited: 'a list) (acc:int): ('a list * weight) = match nodes with |[] -> raise Fail |hd::tl -> let (v,w) = hd in if v = dest then (List.rev(dest::visited),acc+w) else try if (List.m...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (g: 'a graph) (nodes: ('a * weight) list) (dest: 'a) (visited: 'a list) (acc:int) fc sc: ('a list * weight) = match nodes with |[] -> fc () |hd::tl -> let (v,w) = hd in if v = dest then sc (List.rev(dest::visited),acc+w) else let suc2 ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let lst = find_all_paths g a b in let rec helper lst max (answer: ('a list * weight) option) = match lst with |[] -> answer |hd::tl -> let (_,weight) = hd in if weight>max then let answer = Some hd in let max = weight in helper tl max ans...
let open_account (initial_pass: passwd) : bank_account = let failure_counter = ref 0 in let password = ref initial_pass in let balance = ref 0 in {update_pass = (fun passwd new_passwd -> if passwd <> !password then raise wrong_pass else begin failure_counter := 0; password := new_passwd end ); retrieve = (fun passwd am...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun l (n1, n2, w) -> if n1 = vertex then (n2, w)::l else l) [] 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 (n_input, w_input) = node in let neighbour_list = neighbours g n_input in aux_list neighbour_list visited and aux_list (nodes: ('a * weight) list) (visited: 'a list) : (...
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 (n_input, w_input) = node in let neighbour_list = neighbours g n_input in aux_list neighbour_list visited 0 0 and aux_list (nodes: ('a * weight) list) (visited: 'a...
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 counter = ref 0 in let password = ref initial_pass in let balance = ref 0 in {update_pass = (fun oldpwd newpwd -> if oldpwd = !password then let _ = (counter := 0) in (password := newpwd) else let _ = (counter := (!counter + 1)) in raise wrong_pass) ; deposit...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec search l n= match l with |x::xs-> (let (v,v1,w) = x in if v = vertex then search xs ((v1,w) :: n) else if v != vertex then search xs n else search xs n) |_ -> n in search 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) (w: weight) : ('a list * weight) = if List.mem (fst(node)) visited then raise Fail else if fst(node) = b then (List.rev(fst(node)::visited),(w+snd(node))) else (aux_list (neighbours g (fst(node)))...
let find_path' (g: 'a graph) (a: 'a) (b: 'a): ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) w fc sc : ('a list * weight)= if List.mem (fst(node)) visited then fc() else if fst(node) = b then (List.rev(fst(node)::visited),(w+snd(node))) else (aux_list (neighbours g (fst(node))) (fst(node)...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = if List.length(find_all_paths g a b) = 0 then None else let rec compare path longest j i= match path with | [] -> Some(List.nth (find_all_paths g a b) i) | x::xs -> if snd(x) <= longest then compare xs longest (j+1) i else compare xs (snd...
let open_account (initial_pass: passwd) : bank_account = let counter = ref 0 in let password = ref initial_pass in let balance = ref 0 in {update_pass = (fun oldpwd newpwd -> if oldpwd = !password then let _ = (counter := 0) in (password := newpwd) else let _ = (counter := (!counter + 1)) in raise wrong_pass) ; deposit...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec search l n= match l with |x::xs-> (let (v,v1,w) = x in if v = vertex then search xs ((v1,w) :: n) else if v != vertex then search xs n else search xs n) |_ -> n in search 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) (w: weight) : ('a list * weight) = if List.mem (fst(node)) visited then raise Fail else if fst(node) = b then (List.rev(fst(node)::visited),(w+snd(node))) else (aux_list (neighbours g (fst(node)))...
let find_path' (g: 'a graph) (a: 'a) (b: 'a): ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) w fc sc : ('a list * weight)= if List.mem (fst(node)) visited then fc() else if fst(node) = b then (List.rev(fst(node)::visited),(w+snd(node))) else (aux_list (neighbours g (fst(node))) (fst(node)...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = if List.length(find_all_paths g a b) = 0 then None else let rec compare path longest j i= match path with | [] -> Some(List.nth (find_all_paths g a b) i) | x::xs -> if snd(x) <= longest then compare xs longest (j+1) i else compare xs (snd...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let pass_attempts = ref 0 in { update_pass = (fun old_p new_p -> if old_p = !password then (pass_attempts := 0; password := new_p) else (pass_attempts:= !pass_attempts + 1; raise wrong_pass)); deposit = (f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (in_n, out_n, w) l -> if in_n = vertex then (out_n, w) :: l else l) g.edges [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec process_node (node: 'a * weight) (visited : 'a list) (w_acc: int): ('a list * weight) = let (value, weight) = node in if value = b then (List.rev (value::visited), w_acc+weight) else if List.mem value visited then raise Fail else process_list (n...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec process_node (node: 'a * weight) (visited : 'a list) fc (w_acc: int): ('a list * weight)= let (value, weight) = node in if value = b then (List.rev (value::visited), w_acc+weight) else if List.mem value visited then fc () else process_list (nei...
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 max = 0 in let final_path = None in let rec find_max paths max final_path= match paths with | [] -> final_path | hd::remaining -> let (path, weight) = hd in if weight > max then find_max remaining w...
let open_account (initial_pass: passwd) : bank_account = let current_pass = ref initial_pass in let current_balance = ref 0 in let pass_count = ref 0 in {update_pass = (fun pass new_pass -> if pass = !current_pass then begin current_pass := new_pass; pass_count := 0 end else begin pass_count := !pass_count + 1; raise w...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let find_edge l (x, y, w) = if x = vertex then (y, w) :: l else l in List.fold_left find_edge [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, weight) : 'a * weight) (visited : 'a list) : ('a list * weight) = if node = b then ([node], weight) else if List.mem node visited then raise Fail else let (path, cost) = aux_list (neighbours g node) (node :: visited) in (node ::...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, weight) : 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if node = b then sc ([node], weight) else if List.mem node visited then fc () else let sc2 = fun (path, cost) -> sc (node :: path, cost + weight) in aux_lis...
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 | h :: t -> let rec longest_path paths ((longest, max_cost) : 'a list * weight) : 'a list * weight = match paths with | [] -> (longest, max_cost) | (path, cost) :: t -> if ...
let open_account (initial_pass: passwd) : bank_account = let current_pass = ref initial_pass in let current_balance = ref 0 in let pass_count = ref 0 in {update_pass = (fun pass new_pass -> if pass = !current_pass then begin current_pass := new_pass; pass_count := 0 end else begin pass_count := !pass_count + 1; raise w...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let find_edge l (x, y, w) = if x = vertex then (y, w) :: l else l in List.fold_left find_edge [] g.edges ;;