text
stringlengths
0
601k
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, w): 'a * weight) (visited : 'a list) : ('a list * weight) = if node = b then ([b], w) else if List.mem node visited then raise Fail else let adj = neighbours g node in let (node_path, total_weight) = aux_list adj (node :: visite...
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 ([b], w) else if List.mem node visited then fc () else let adj = neighbours g node in let sc2 = fun (node_path, total_weight) -> sc (node :: n...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | hd :: tl -> Some (List.fold_left ( fun (lpath, lweight) (path, weight) -> if weight > lweight then (path, weight) else (lpath, lweight) ) hd tl);;
let open_account (initial_pass: passwd) : bank_account = let passwd = ref initial_pass in let balance = ref 0 in let incorrect_passwd_count = ref 0 in let update_pass_func old_passwd new_passwd = if old_passwd = !passwd then ( incorrect_passwd_count := 0; passwd := new_passwd ) else ( incorrect_passwd_count := !incorre...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let is_correct_edge edge = let departure, destination, cost = edge in departure = vertex in let correct_edges = List.filter is_correct_edge g.edges in let edge_to_tuple edge = let (dep, dest, cost) = edge in (dest, cost) in List.map edge_to_tuple correct_...
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 (dest, cost) = node in let not_visited neighbour = let (dest, cost) = neighbour in not (List.mem dest visited) in let next_node_options = (List.filter not_vi...
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) fail succeed : ('a list * weight) = let (dest, cost) = node in let not_visited neighbour = let (dest, cost) = neighbour in not (List.mem dest visited) in let next_node_options = (List...
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_longest (ls : ('a list * weight) list) (longest : ('a list * weight)) : ('a list * weight) option = match ls with | [] -> Some(longest) | x :: xs -> let (longest_ls, longest_cost) = lon...
let open_account (initial_pass: passwd) : bank_account = let passwd = ref initial_pass in let balance = ref 0 in let incorrect_passwd_count = ref 0 in let update_pass_func old_passwd new_passwd = if old_passwd = !passwd then ( incorrect_passwd_count := 0; passwd := new_passwd ) else ( incorrect_passwd_count := !incorre...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let is_correct_edge edge = let departure, destination, cost = edge in departure = vertex in let correct_edges = List.filter is_correct_edge g.edges in let edge_to_tuple edge = let (dep, dest, cost) = edge in (dest, cost) in List.map edge_to_tuple correct_...
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 (dest, cost) = node in let not_visited neighbour = let (dest, cost) = neighbour in not (List.mem dest visited) in let next_node_options = (List.filter not_visited (neigh...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fail succeed : ('a list * weight) = let (dest, cost) = node in let not_visited neighbour = let (dest, cost) = neighbour in not (List.mem dest visited) in let next_node_options = (List.filter not_...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_longest (ls : ('a list * weight) list) (longest : ('a list * weight)) : ('a list * weight) option = match ls with | [] -> Some(longest) | x :: xs -> let (longest_ls, longest_cost) = longest in let (ls, cost) = x in if cost > ...
let open_account (initial_pass: passwd) : bank_account = let update_ref (nref: int ref) (n : int) = nref := n; in let attempts = ref 0 in let balance = ref 0 in let account = ref initial_pass in { update_pass = (fun oldP newP -> if(String.equal oldP !account) then let a = (update_ref attempts 0) in account := newP; els...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let check (v1 : 'a) (v2 : 'a) = ((compare v1 v2) = 0) in let rec helper (edges: ('a * 'a * weight) list) (vertex: 'a) (acc : ('a * weight) list)= match edges with |[] -> acc |hd::tl -> let (v1, v2, w) = hd in match (v1, v2, w) with |(v1, v2, w) when (chec...
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 password = ref initial_pass and account_balance = ref 0 and wrong_pass_cnt = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if old_pass = !password then (wrong_pass_cnt := 0; password := new_pass) else (wrong_pass_cnt := !wrong_pass_cn...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (v1, v2, w) a -> if v1 = vertex then (v2,w)::a else a) 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 city = fst(node) and fcost = snd(node) in if city = b then ([b] , fcost) else if (List.mem city visited) then raise Fail else (let (path , cost) = aux_list (neighbours g...
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 city = fst(node) and fcost = snd(node) in if city = b then sc ([b], fcost) else if (List.mem city visited) then fc () else aux_list (neighbours g city) (city::visi...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec min x = match x with | [] -> None | [(o,d)] -> Some (o,d) | (o1,d1)::(o2,d2)::tail -> if d1 >= d2 then min((o1,d1)::tail) else min((o2,d2)::tail) in min(find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass and balance = ref 0 and error_count = ref 0 in { update_pass = (fun old_pass new_pass -> if String.equal old_pass !password then password := new_pass else begin error_count := !error_count+1; raise wrong_pass; end ); deposit = (fun...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x (v1,v2,w) -> if vertex = v1 then (v2,w)::x else x) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let acc:(('a list * weight) ref) = ref ([a], 0) in let remove_last (list,_) = let rec helper list = match list with | [] | _::[] -> [] | x::xs -> x::(helper xs) in helper list in let update_acc (vertex, node_weight) = let {contents = (path, path_weight)...
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) = if (fst node) = b then sc ([],0) else let not_visited visited edge = let (v2,_) = edge in List.for_all (fun x -> not (String.equal v2 x)) visited in let potential_nod...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max = ref ([],0) in let rec longest_path list = match list with | [] -> if (snd !max = 0) then None else Some !max | x::xs -> if (snd x) > (snd !max) then begin max := ((fst x), (snd x)); longest_path xs end else longest_path xs in lo...
let open_account (initial_pass: passwd) : bank_account = let money = ref 0 in let password = ref initial_pass in let attempt_count = ref 0 in { update_pass = (fun (old_pswd: passwd) (new_pswd: passwd) -> if old_pswd = !password then let _ = (attempt_count := 0) in password := new_pswd else let _ = (attempt_count := !at...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec filter ((f,s,w): 'a * 'a * weight) = f = vertex in let rec update ((f,s,w): 'a * 'a * weight) : ('a * weight) = (s,w) in List.map update (List.filter filter g.edges);;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec sum (visited: ('a * weight) list) : weight = match visited with | [] -> 0 | x::xs -> (snd x) + sum xs in let get_path (visited: ('a * weight) list): ('a list) = List.rev (List.map fst visited) in let rec aux_node (node: 'a * weight) (visited : (...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec sum (visited: ('a * weight) list) : weight = match visited with | [] -> 0 | x::xs -> (snd x) + sum xs in let get_path (visited: ('a * weight) list): ('a list) = List.rev (List.map fst visited) in let rec aux_node (node: 'a * weight) (visited : ...
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 | _ -> let sorted = List.sort (fun x y -> if (snd x) > (snd y) then 1 else 0) all_paths in Some (List.hd sorted);;
let open_account (initial_pass: passwd) : bank_account = let pas = ref initial_pass in let incorrect = ref 0 in let balance = ref 0 in { update_pass = (fun pass now -> if pass = !pas then (pas := now; incorrect := 0) else (incorrect := !incorrect + 1; raise wrong_pass;) ); retrieve = (fun pass n -> if !incorrect < 5 th...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if g.edges = [] || g.nodes = [] then [] else let f edge acc = let (a,b,w) = edge in if a = vertex then (b,w) :: acc else acc in List.fold_right f 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) = let (e,w) = node in if e = b then b::visited,(acc+w) else if List.mem e visited || e = a then raise Fail else try aux_list (neighbours g e) (e::visited) (acc+w)...
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 (e,w) = node in if e = b then sc ([b],w) else if List.mem e visited then fc () else aux_list (neighbours g e) (e::visited) fc (fun (path, cost) -> sc ( e :: path, ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let n = find_all_paths g a b in let f (x,y) final= let (ls,b) = List.hd final in if y > b || ( y = b && List.length x > List.length ls) then [(x,y)] else final in match n with | [] -> None | _-> let s = List.fold_right f n [List.hd n] in ...
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let failures = ref 0 in let balance = ref 0 in let update_pass cur_pass new_pass : unit = if (cur_pass = !pass) then (pass := new_pass; failures := 0) else (failures := (!failures+1); raise wrong_pass) in let retrieve cur_pass amoun...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let is_neighbour a b = let get_v1 (v1,_,_) = v1 in let get_v2 (_,v2,_) = v2 in let get_w (_,_,w) = w in if (vertex = (get_v1 b)) then ((get_v2 b),(get_w b)) :: a else a in List.fold_left is_neighbour [] 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) = if ((fst node) = b) then (((fst node) :: []),(snd node)) else ( let neigh = List.map (fun f -> (fst f ,((snd f) + (snd node)))) (neighbours g (fst node)) in let path = aux_l...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) sc fc : ('a list * weight) = if ((fst node) = b) then sc (((fst node) :: []),(snd node)) else ( let neigh = List.map (fun f -> (fst f ,((snd f) + (snd node)))) (neighbours g (fst node)) in aux_li...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec rec_path all_paths acc = match all_paths with |[] -> if (acc = ([],0)) then None else Some acc |hd :: tl -> if ((snd hd) > (snd acc)) then rec_path tl hd else rec_path tl acc in rec_path (find_all_paths g a b) ([],0);;
let open_account (initial_pass: passwd) : bank_account = let balance= ref 0 in let attempts= ref 0 in let pass= ref initial_pass in { update_pass = (fun (correctpass:passwd ) (new_pass: passwd)-> if (correctpass = !pass) then (attempts := 0; pass := new_pass) else (attempts := !attempts + 1; (raise wrong_pass))); depos...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun (neighbours: ('a * weight) list) (edgenodes: ('a * 'a * weight))-> let (v,v2,w) = edgenodes in if not(v = vertex) then neighbours else (v2,w) :: 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 (v2, weight) = node in if v2 = b then (([v2]), ( weight)) else if List.mem v2 visited then raise Fail else let (anode, w)= aux_list(neighbours g v2) (visited @ [v2]) in ...
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 local_pass = ref initial_pass in let local_balance = ref 0 in let local_try = ref 0 in {update_pass = (fun passwd1 passwd2 -> if passwd1 = !local_pass then ( local_pass := passwd2; local_try := 0 ) else ( local_try := !local_try + 1; raise wrong_pass ) ); ret...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get_result (result: ('a * weight) list) (edge: ('a * 'a * weight)) = let (v1, v2, w) = edge in if v1 = vertex then (v2, w)::result else result in List.fold_left get_result [] 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 (List.rev (v::(List.rev visited)), w) else let (path, weight) = aux_list (neighbours g v) (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 (v, w) = node in if v = b then sc v w else if List.mem v visited then fc () else let (l, weight) = sc v w in let sc2 = fun x y -> (List.rev (x::(List.rev l)), y+we...
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_max paths max = match paths with | [] -> max | hd :: tl -> let (l,w) = hd in match max with | None -> find_max tl (Some hd) | Some (_,w2) -> if w >= w2 then find_max tl (Some (l,w)) els...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let counter = ref 0 in let dep = ref 0 in { update_pass = (fun pw new_pw -> if !password = pw then (counter := 0; password := new_pw) else (counter := !counter + 1;raise wrong_pass)); retrieve = (fun pw amount -> if !counter = 5...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let extract = fun vertex edge -> match edge with | (a,b,w) when a = vertex -> (b,w) in let rec find = fun vertex edge -> match edge with | (a,b,w) when a = vertex -> true | _ -> false in List.map (extract vertex) (List.filter (find 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) = if List.mem (fst node) visited then raise Fail else if (fst node) = b then (b::visited, snd node) else let tmp = aux_list (neighbours g (fst node)) ((fst node)::visited) in ...
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) = if List.mem (fst node) visited then fc () else if (fst node) = b then sc (b::visited, snd node) else aux_list (neighbours g (fst node)) ((fst node)::visited) fc (fun ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l = find_all_paths g a b in let rec find_longest list max_length count max output = match list with | [] -> Some output | x::xs -> if (snd x) > max_length then (find_longest xs (snd x) (count+1) count x) else (find_longest xs max_leng...
let open_account (initial_pass: passwd) : bank_account = let passwd = ref initial_pass in let balance = ref 0 in let counter = ref 0 in { update_pass = (fun old_pass new_pass-> if (old_pass <> !passwd) then counter := !counter + 1; if (old_pass = !passwd) then passwd := new_pass else raise wrong_pass; if (!counter > 0)...
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 passwd = ref initial_pass in let balance = ref 0 in let counter = ref 0 in { update_pass = (fun old_pass new_pass-> if (old_pass <> !passwd) then counter := !counter + 1; if (old_pass = !passwd) then passwd := new_pass else raise wrong_pass; if (!counter > 0)...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let fun1 x = match x with |(a,b,c) -> if (a = vertex) then true else false in let fun2 x = match x with |(a,b,c) -> (b,c) in List.map fun2 (List.filter (fun1) (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 balance = ref 0 in let wrong = ref 0 in let pass= ref initial_pass in {update_pass = (fun old neww-> if !pass=old then (let x= (pass:=neww) in wrong:=0) else (let x=(wrong :=!wrong + 1) in raise wrong_pass)); deposit = (fun pw amount -> if (!wrong >= 5) then ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec aux_node l acc (w: weight) v = match l with |[]-> acc |(v1,v2,w1) :: xs -> if v1=v then aux_node xs (List.append acc [v2, w1]) (w+w1) v else aux_node xs acc w v in aux_node g.edges [] 0 vertex;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let destinations = neighbours g in let rec aux_list (nodes: ('a * weight) list) (visited: 'a list) (w: weight) : ('a list * weight) = match nodes with |[]-> raise Fail |(v,w1) ::xs ->let x=(v,w1) in if v=b then (List.append visited [b]), (w+w1) else (if...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let destinations = neighbours g in let rec aux_list (nodes: ('a * weight) list) (visited: 'a list) (w: weight) fc sc : ('a list * weight) = match nodes with |[]-> fc () |(v,w1) ::xs -> if v=b then sc (visited, b, w, w1) else if (List.mem v visited) the...
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 rec f l max_path = match l with |[]->max_path |(l1, w1) :: xs-> let (l2,w2)=max_path in if w1>w2 then f xs (l1,w1) else f xs max_path in Some (f l ([], 0));;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let attempts = ref 0 in let balance = ref 0 in let update_pass (old_pass: passwd) (new_pass: passwd) = if (old_pass = !password) then (password := new_pass; attempts := 0) else (attempts := !attempts + 1; (raise wrong_pass)) in ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let findNeigh a (v0, v1, weight) = if v0 = vertex then (v1, weight)::a else a in List.fold_left findNeigh [] 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, weight) = node in if n = b then (visited@[b], weight) else if List.exists (fun a -> n = a) visited then raise Fail else let update_weight (x, x_w) = (x, x_w + weight...
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, weight) = node in if n = b then sc ([b], weight) else if List.exists (fun a -> n = a) visited then fc () else let cur_neigh = (neighbours g n) in aux_list cur_...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match (find_all_paths g a b) with | [] -> None | hd::tl -> Some (List.fold_right (fun ((_,weight1) as first) ((_,weight2) as second) -> if weight1 > weight2 then first else second) tl hd);;
let open_account (initial_pass: passwd) : bank_account = let attempt = ref 0 in let password = ref initial_pass in let current_balance = ref 0 in { update_pass = (fun cur_pass new_pass -> if cur_pass = !password then (attempt := 0; password := new_pass) else (attempt := !attempt + 1; raise wrong_pass)) ; retrieve = (fu...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec get_neighbours edges vertex acc = match edges with | [] -> acc | (v1, v2, w) :: tl -> if v1 = vertex then get_neighbours tl vertex ((v2, w) :: acc) else get_neighbours tl vertex acc in get_neighbours 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) tw : ('a list * weight) = if List.mem (fst node) (visited) then raise Fail else if (fst node) = b then (List.rev (fst node :: visited), snd node + tw) else aux_list (neighbours g (fst node)) ((fst...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc tw : ('a list * weight)= if List.mem (fst node) (visited) then fc () else if (fst node) = b then (List.rev (fst node :: visited), snd node + tw) else aux_list (neighbours g (fst node)) ((fst 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 maximum = let rec get_max acc list = match list with | [] -> acc | (p, w) :: tl -> get_max (max acc w) tl in get_max 0 all_paths in let result = let rec get_longest (list: ('a list * weight) lis...
let open_account (initial_pass: passwd) : bank_account = let pswd = ref initial_pass in let bal = ref 0 in let attempts = ref 0 in { update_pass = (fun old_pass new_pass -> if String.equal old_pass !pswd then let _ = attempts := 0 in pswd := new_pass else let _ = attempts := !attempts + 1 in raise wrong_pass); retrieve...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (a,b,c) -> fun ls -> if a = vertex then (b,c) :: ls else ls) 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) = match node with | (n, w) when n = b -> ([b], w) | (n, w) when List.exists ((=) n) visited -> raise Fail | (n, w) -> (try let (path, wt) = aux_list (neighbours g n) (n :: vis...
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)= match node with | (n, w) when n = b -> sc ([b], w) | (n, w) when List.exists ((=) n) visited -> fc () | (n, w) -> let success = (fun (ls, wt) -> sc (n :: ls, w + wt)) ...
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 lock = ref false in let failureCount = ref 0 in let currentBalance = ref 0 in let currentPassword = ref initial_pass in { update_pass = (fun old_pass new_pass -> if old_pass <> !currentPassword then (incr failureCount ; raise wrong_pass ) else (failureCount:=...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let funct = (fun l edge-> (let (a,b,c)=edge in (if (vertex = a) then( (b,c)::l) else l))) in List.fold_left funct [] 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) (sum : int): ('a list * weight) = let (z,t) = node in if z = b then (List.rev_append visited [z], t + sum) else( if List.mem z visited then raise Fail else aux_list (neighbours g z) (z::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 (z,t) = node in if z = b then sc ([z],t) else (if List.mem z visited then fc () else aux_list (neighbours g z) (z :: visited) fc (fun(z2,t2)-> sc (z:: z2,t2+t))) a...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let find list = match list with |[] -> None | hd :: tl -> Some hd in let listOfAllPaths = find_all_paths g a b in let f = fun(z,t)(z2,t2)->compare t t2 in let sorted = List.sort f listOfAllPaths in find (List.rev sorted);;
let open_account (initial_pass: passwd) : bank_account = let amount = ref 0 in let pass = ref initial_pass in let time_fail = ref 0 in let if_lock = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (old_pass = !pass) then begin pass := new_pass; time_fail := 0; if_lock := 0 end else begin time_...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f (acc) (b:('a * 'a * weight)) = match b with | (b1,b2,bw) when b1 = vertex -> ([(b2,bw)] @acc) | _ -> acc in List.fold_left f [] 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) = if fst(node) = b then ([fst(node)],snd(node)) else if List.mem (fst(node)) visited then raise Fail else let (p,w ) = aux_list (neighbours (g) (fst(node))) (fst(node)::visite...
let find_path' (g: 'a graph) (a: 'a) (b: 'a)= let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if fst(node) = b then sc ([fst(node)],snd(node)) else if List.mem (fst(node)) visited then fc () else aux_list (neighbours g (fst(node))) (fst(node)::visited) fc (fun (p, w) -> sc (fst(node...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let the_max l1 l2 = if (List.length (fst(l1)) >= List.length (fst(l2))) then l1 else l2 in let rec find_max list: ('a list * weight) option = match list with |[] -> None |hd::tl -> begin match find_max tl with |None -> Some hd |Some m -> ...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let incorrect_attempts = ref 0 in let account_blocked = ref false in let check_pass (pass: passwd) f is_update_pass = if pass = !password && not (!account_blocked) then ( incorrect_attempts := 0; f ) else ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f a el = let (from_, to_, weight_) = el in (to_, weight_) :: a in let filter el = let (from_, to_, weight_) = el in from_ = vertex in let edges = List.filter filter g.edges in List.fold_left f [] edges ;;