text
stringlengths
0
601k
let open_account (initial_pass: passwd) : bank_account = let curr_pass = ref initial_pass in let balance = ref 0 in let fails = ref 0 in let check_pass = function pass -> if !fails = 5 then raise too_many_failures else if pass = !curr_pass then (fails := 0; true) else (fails := 1 + !fails; false) in let update_pass = f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec filter edges vertex acc = match edges with | [] -> acc | x::xs -> let v1,v2,w = x in if v1 = vertex then filter xs vertex ((v2,w)::acc) else filter xs vertex acc in filter 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 rec contains x l = match l with | [] -> false | h::t -> h=x || contains x t in let n,w = node in if contains n visited then raise Fail else if n = b then ([b],w) else 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 n,w = node in let rec contains x l = match l with | [] -> false | h::t -> h=x || contains x t in if contains n visited then fc() else if n = b then sc([b], w) else...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_longest l = match l with | [] -> None | [single_el] -> Some single_el | h::xs when xs <> [] -> let m::t = xs in let (p1,w1) = h in let (p2,w2) = m in match w1 >= w2 with | true -> find_longest ((p1,w1)::t) | false -> find_lon...
let open_account (initial_pass: passwd) : bank_account = let curr_pass = ref initial_pass in let curr_balance = ref 0 in let fail_counter = ref 0 in let correct_pass = (function x -> if x = !curr_pass then (fail_counter := 0; true) else (fail_counter := !fail_counter + 1; false)) in let raise_errors = (function x -> if...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if not (List.exists ((=) vertex) g.nodes) then [] else List.fold_left (fun lst (_,v2,w) -> lst @ [(v2, w)]) [] (List.filter (function (v1, _, _) -> v1 = vertex) g.edges);;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if not (List.exists ((=) a) g.nodes) || not (List.exists ((=) b) g.nodes) then raise Fail else if a = b then ([a], 0) else let weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v, w) = node in weight ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if not (List.exists ((=) a) g.nodes) || not (List.exists ((=) b) g.nodes) then raise Fail else if a = b then ([a], 0) else let weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v, w) = node in w...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max_weight = ref 0 in let get_paths = find_all_paths g a b in match get_paths with |[] -> None |_ -> let _ = (List.exists (fun (_, cost) -> if cost > !max_weight then (max_weight := cost; false) else false) get_paths) in let res = (Li...
let open_account (initial_pass: passwd) : bank_account = let balance, pass, fails = ref 0, ref initial_pass, ref 0 in { update_pass = (fun oldpass newpass -> if oldpass <> !pass then (fails := !fails + 1; raise wrong_pass) else (pass := newpass; fails := 0)) ; retrieve = (fun pwd amt -> if !fails = 5 then raise too_man...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let h x acc = match x with |(v1, v2, w) -> if vertex = v1 then (v2, w)::acc else acc in List.fold_right h g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (acc: weight) (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v,w) = node in if (List.mem v visited) then raise Fail else if (b = v) then (visited@[v], acc+w) else aux_list (acc+w) (neighbours g v) (visited@[v]) ; an...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (acc: weight) (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 ( b = v ) then sc (visited@[v], acc+w) else aux_list (acc+w) (neighbours g v) (visited@[...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f (optimal) (l,w)= match optimal with | None -> Some(l,w) | Some(maxPath, maxWeight) -> if (w > maxWeight) then Some(l,w) else Some(maxPath, maxWeight) in List.fold_left f None (find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let c = ref 0 in let passwd = ref initial_pass in let balance = ref 0 in {update_pass = (fun pwd1 pwd2 -> if pwd1 = !passwd then let _ = (c := 0) in (passwd := pwd2) else let _ = (c := (!c + 1)) in raise wrong_pass); deposit=(fun p amount -> if p = !passwd && (!c...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec temp list solution= match list with |x::xs-> (let (vertex_1,vertex_2,w) = x in if not(vertex_1 = vertex) then temp xs solution else temp xs ((vertex_2,w) :: solution)) |_ -> solution in temp 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 : ('a list * weight) = let _ = node in if fst(node)=b then (List.rev(fst(node)::visited),(w+(snd(node)))) else if not (List.mem (fst(node)) visited) then (aux_list (neighbours g (fst(node))) (fs...
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)= let _ = node in if fst(node)=b then (List.rev(fst(node)::visited),(w+(snd(node)))) else if not (List.mem (fst(node)) visited) then (aux_list (neighbours g (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 search p solution k y= match p with | [] -> Some(List.nth (find_all_paths g a b) y) | x::xs -> if snd(x) < solution then search xs solution (k+1) y else if snd(x) = solution ...
let open_account (initial_pass: passwd) : bank_account = let attempts = ref 0 in let password = ref initial_pass in let balance = ref 0 in { update_pass = (fun x-> (fun y-> if !password <> x then let p = (attempts := !attempts+1; raise(wrong_pass)) in p else let w = (attempts := 0; password := y) in w )); retrieve = ( ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find (l:('a * 'a * weight) list) (node: 'a) (acc: ('a * weight) list) : ('a * weight) list = match l with | [] -> acc | hd:: tl -> let (a,b,c) = hd in if a = node then find tl node (acc @ [(b,c)]) else find tl node acc in find 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 (c,d) =node in if c = b then (visited,d) else let neighbourlist = neighbours g c in let neighbourlist = List.map (fun (x,y) -> (x,y+d)) neighbourlist in aux_list neighbo...
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 (c,d) =node in if c = b then sc (visited,d) else let neighbourlist = neighbours g c in let neighbourlist = List.map (fun (x,y) -> (x,y+d)) neighbourlist in aux_lis...
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 sorted = List.sort (fun (x,y)-> (fun (z,w)-> y-w)) allpaths in let sorted = List.rev sorted in let max = List.nth sorted 0 in Some max;;
let open_account (initial_pass: passwd) : bank_account = let attempts = ref 0 in let password = ref initial_pass in let balance = ref 0 in { update_pass = (fun x-> (fun y-> if !password <> x then let p = (attempts := !attempts+1; raise(wrong_pass)) in p else let w = (attempts := 0; password := y) in w )); retrieve = ( ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find (l:('a * 'a * weight) list) (node: 'a) (acc: ('a * weight) list) : ('a * weight) list = match l with | [] -> acc | hd:: tl -> let (a,b,c) = hd in if a = node then find tl node (acc @ [(b,c)]) else find tl node acc in find 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 (c,d) =node in if c = b then (visited,d) else let neighbourlist = neighbours g c in let neighbourlist = List.map (fun (x,y) -> (x,y+d)) neighbourlist in aux_list neighbo...
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 (c,d) =node in if c = b then sc (visited,d) else let neighbourlist = neighbours g c in let neighbourlist = List.map (fun (x,y) -> (x,y+d)) neighbourlist in let suc...
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 sorted = List.sort (fun (x,y)-> (fun (z,w)-> y-w)) allpaths in let sorted = List.rev sorted in let max = List.nth sorted 0 in Some max;;
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let wrong_time = ref 0 in let money = ref 0 in let update_pass oldp newp = if oldp = !pass then (pass := newp ; wrong_time := 0) else (wrong_time := !wrong_time +1 ; raise wrong_pass) in let deposit pw amount= if !wrong_time >= 5 th...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let add tup vertex lis = match tup with |(a,b,c) when a = vertex -> (b,c)::lis | _ -> lis in let rec mat edges vertex lis = match edges with |x::xs -> mat xs vertex (add x vertex lis) |[] -> lis in mat (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) (acc:weight): ('a list * weight) = let (a,w) = node in if List.mem a visited then raise Fail else if a = b then (visited@[a],w+acc) else aux_list (neighbours g a) (visited@[a]) (acc+w) and aux_lis...
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) fc sc : ('a list * weight)= let (a,w) = node in if List.mem a visited then raise Fail else if a = b then (fc visited,sc acc) else aux_list (neighbours g a) (fc visited) (sc acc) fc s...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let wei = ([],0) in let all_path = find_all_paths g a b in let rec findmax all_path wei = match all_path with |[] -> let (a,w) = wei in if w = 0 then None else Some(wei) |x::xs -> let (_,w) = x in let (_,w1) = wei in if w1 < w then findma...
let open_account (initial_pass: passwd) : bank_account = let oldpass = ref initial_pass in let balance = ref 0 in let errors = ref 0 in { update_pass = (fun a b -> if a = !oldpass then (oldpass := b ; errors := 0) else (errors := !errors + 1 ; raise wrong_pass)); retrieve = (fun a b -> if !errors >= 5 then raise too_ma...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x (v,n,w) -> if v = vertex then (n,w) :: x else 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) : ('a list * weight) = let (n,we) = node in if (List.exists (fun x -> x = n) visited) then raise Fail else if n = b then ((n::visited),we) else let (al,w) = aux_list (neighbours g n) (n::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 (n,we) = node in let (al,w) = sc n we in if n = b then (al,w) else let fc2 = fc in let sc2 = fun x y -> (x::al,y+w) in aux_list (neighbours g n) al fc2 sc2 and aux...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = if (find_all_paths g a b) = [] then None else let rec findmax l (cl,cw)= match l with |[] -> (cl,cw) |(l,w)::xs -> if w > cw then findmax xs (l,w) else findmax xs (cl,cw) in Some (findmax (find_all_paths g a b) ([],0));;
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let fails = ref 0 in let verification password func = if !pass = password then (fails := 0; func ()) else (fails := (!fails + 1); raise wrong_pass) in let update_pass old_pass new_pass = verification old_pass ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1, v2, w) -> if vertex = v1 then (v2, w) :: 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) (path : 'a list) (cost : int) : ('a list * weight) = match node with | (v, w) -> if v = b then (path @ [v], cost + w) else if List.mem v visited then raise Fail else aux_list (neighbours g v) ([v]...
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 | (v, w) -> if v = b then sc ([v], w) else if List.mem v visited then fc () else aux_list (neighbours g v) (v :: visited) fc (fun (path, cost) -> sc ([...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest l = match l with | [] -> None | [(path, cost)] -> Some (path, cost) | (p1, c1) :: (p2, c2) :: t -> if c1 <= c2 then longest ((p2, c2) :: t) else longest ((p1, c1) :: t) in longest (find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let count = ref 0 in {update_pass = (fun p1 p2 -> if p1 = !password then let _ = (count := 0) in (password := p2) else let _ = (count := (!count + 1)) in raise wrong_pass) ; retrieve = (fun p amount -> if ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l result= match l with |x::xs-> (let (v1,v2,w) = x in if v1 = vertex then helper xs ((v2,w) :: result) else helper xs result) |_ -> result 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) (w:weight): ('a list * weight) = match (neighbours g (fst(node))) with | [] -> raise Fail | x::xs -> if fst(x) = b then (List.rev((fst(x)::fst(node)::visited)),w+snd(node)+snd(x)) else if (List.me...
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) fc sc : ('a list * weight)= match (neighbours g (fst(node))) with | [] -> fc () | x::xs -> if fst(x) = b then (List.rev((fst(x)::fst(node)::visited)),w+snd(node)+snd(x)) else if (List....
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 helper l max i index= match l with | [] -> Some(List.nth l index) | x::xs -> if snd(x) > max then helper xs (snd(x)) (i+1) (i) else helper xs max (i+1) index in helper (find_...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let count = ref 0 in {update_pass = (fun p1 p2 -> if p1 = !password then let _ = (count := 0) in (password := p2) else let _ = (count := (!count + 1)) in raise wrong_pass) ; retrieve = (fun p amount -> if ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l result= match l with |x::xs-> (let (v1,v2,w) = x in if v1 = vertex then helper xs ((v2,w) :: result) else helper xs result) |_ -> result 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) (w:weight): ('a list * weight) = match (neighbours g (fst(node))) with | [] -> raise Fail | x::xs -> if fst(x) = b then (List.rev((fst(x)::fst(node)::visited)),w+snd(node)+snd(x)) else if (List.me...
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) fc sc : ('a list * weight)= match (neighbours g (fst(node))) with | [] -> fc () | x::xs -> if fst(x) = b then (List.rev((fst(x)::fst(node)::visited)),w+snd(node)+snd(x)) else if (List....
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 helper l max i index= match l with | [] -> Some(List.nth (find_all_paths g a b) index) | x::xs -> if snd(x) > max then helper xs (snd(x)) (i+1) (i) else helper xs max (i+1) i...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let count = ref 0 in {update_pass = (fun p1 p2 -> if p1 = !password then let _ = (count := 0) in (password := p2) else let _ = (count := (!count + 1)) in raise wrong_pass) ; retrieve = (fun p amount -> if ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l result= match l with |x::xs-> (let (v1,v2,w) = x in if v1 = vertex then helper xs ((v2,w) :: result) else helper xs result) |_ -> result 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) (w:weight): ('a list * weight) = match (neighbours g (fst(node))) with | [] -> raise Fail | x::xs -> if fst(x) = b then (List.rev((fst(x)::fst(node)::visited)),w+snd(node)+snd(x)) else if (List.me...
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) fc sc : ('a list * weight)= match (neighbours g (fst(node))) with | [] -> fc () | x::xs -> if fst(x) = b then (List.rev((fst(x)::fst(node)::visited)),w+snd(node)+snd(x)) else if (List....
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 helper l max i index= match l with | [] -> Some(List.nth (find_all_paths g a b) index) | x::xs -> if snd(x) > max then helper xs (snd(x)) (i+1) (i) else helper xs max (i+1) i...
let open_account (initial_pass: passwd) : bank_account = let account_pass = ref initial_pass in let balance = ref 0 in let tries = ref 0 in { update_pass = (fun old_pass new_pass -> if !account_pass = old_pass then (account_pass := new_pass; tries := 0) else (tries := !tries + 1; raise wrong_pass)); retrieve = (fun pas...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges vertex acc = match edges with | [] -> acc | (a, b, w)::t -> if vertex = a then helper t vertex ((b, w)::acc) else helper t vertex acc in helper 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) (w : weight): ('a list * weight) = if (fst node) = b then (visited@[(fst node)], (w+(snd node))) else aux_list (neighbours g (fst node)) (visited@[(fst node)]) (w+(snd node)) and aux_list (nodes: ...
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 (visited@[(fst node)], (sc (snd node))) else let sc2 = fun x -> sc (x+(snd node)) in aux_list (neighbours g (fst node)) (visited@[(fst node)]) fc...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper paths highest = match paths with | [] -> if highest = ([], 0) then None else Some highest | (a, w)::t -> if w > (snd highest) then helper t (a, w) else helper t highest in helper (find_all_paths g a b) ([], 0);;
let open_account (initial_pass: passwd) : bank_account = let failure = ref 0 in let cur = ref 0 in let pwd = ref initial_pass in {update_pass = (fun (a: passwd)->(fun (b:passwd) -> if a = !pwd then (pwd := b; failure := 0;) else (incr failure; raise wrong_pass;);)); retrieve = (fun (c: passwd) -> (fun (d: int) -> if !f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun y x -> let (v1, v2, w) = x in if v1 = vertex then (v2,w)::y else y) [] 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) (w0: int) (target: 'a): ('a list * weight) = let (n,w) = node in if List.mem n visited then raise Fail else if n == target then (visited@[n],w0+w) else (try aux_list (neighbours g n) (visited@[n])...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (w0: int) (target: 'a) fc sc : ('a list * weight)= let (n,w) = node in if List.mem n visited then fc () else if n == target then sc (visited@[n],w0+w) else aux_list (neighbours g n) (visited@[n])...
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 failure = ref 0 in let cur = ref 0 in let pwd = ref initial_pass in {update_pass = (fun (a: passwd)->(fun (b:passwd) -> if a = !pwd then (pwd := b; failure := 0;) else (incr failure; raise wrong_pass;);)); retrieve = (fun (c: passwd) -> (fun (d: int) -> if !f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun y x -> let (v1, v2, w) = x in if v1 = vertex then (v2,w)::y else y) [] 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) (w0: int) (target: 'a): ('a list * weight) = let (n,w) = node in if List.mem n visited then raise Fail else if n == target then (visited@[n],w0+w) else (try aux_list (neighbours g n) (visited@[n])...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (w0: int) (target: 'a) fc sc : ('a list * weight)= let (n,w) = node in if List.mem n visited then fc () else if n == target then sc (visited@[n],w0+w) else aux_list (neighbours g n) (visited@[n])...
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 : passwd ref = ref initial_pass in let bal : int ref = ref 0 in let auth_fail : int ref = ref 0 in let locked : bool ref = ref false in { update_pass = (fun (old_p: passwd) (new_p: passwd) -> if (old_p = !password) then (password := new_p; auth_fail ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (_, v2, w) -> (v2, w)) (List.filter (fun (v, _, _) -> v = vertex) g.edges) ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let remove_vis (nodes: ('a * weight) list) (vis:'a list) : ('a * weight) list = let filter (v, _) = not (List.exists (fun v1 -> v1 = v) vis) in List.filter filter nodes in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight)= if...
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 node else ( let suc2 = ( fun (n: 'a * weight) -> let k = sc node in ((fst k) @ [fst n], snd k + snd n) ) in aux_list (neighbours g (fst node))...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths: ('a list * weight) list = find_all_paths g a b in if all_paths = [] then None else Some (List.hd (List.sort (fun (_, x) (_, y) -> y - x) all_paths)) ;;
let open_account (initial_pass: passwd) : bank_account = let password : passwd ref = ref initial_pass in let bal : int ref = ref 0 in let auth_fail : int ref = ref 0 in let locked : bool ref = ref false in { update_pass = (fun (old_p: passwd) (new_p: passwd) -> if (old_p = !password) then (password := new_p; auth_fail ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (_, v2, w) -> (v2, w)) (List.filter (fun (v, _, _) -> v = vertex) g.edges) ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let remove_vis (nodes: ('a * weight) list) (vis:'a list) : ('a * weight) list = let filter (v, _) = not (List.exists (fun v1 -> v1 = v) vis) in List.filter filter nodes in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight)= if...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let remove_vis (nodes: ('a * weight) list) (vis:'a list) : ('a * weight) list = let filter (v, _) = not (List.exists (fun v1 -> v1 = v) vis) in List.filter filter nodes in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weig...
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let paths : ('a list * weight) list ref = ref [] in let remove_vis (nodes: ('a * weight) list) (vis:'a list) : ('a * weight) list = let filter (v, _) = not (List.exists (fun v1 -> v1 = v) vis) in List.filter filter nodes in let rec aux_node (n...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let remove_vis (nodes: ('a * weight) list) (vis:'a list) : ('a * weight) list = let filter (v, _) = not (List.exists (fun v1 -> v1 = v) vis) in List.filter filter nodes in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : (...
let open_account (initial_pass: passwd) : bank_account = notimplemented () ;;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let wrong = ref 0 in let update_pass old_pass new_pass = if old_pass = !password then let _ = wrong := 0 in password := new_pass else match !wrong with | 5 -> raise wrong_pass | _ -> let _ = wrong := ((!wr...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes; edges} = g in match (nodes, edges) with | ([], []) | (_, []) | ([], _) -> [] | _ -> let choose list (v1, v2, weight) = if vertex = v1 then (v2, weight)::list else list in List.fold_left choose [] 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 (pos, w) = node in if List.mem pos visited then raise Fail else if pos = b then (pos::visited, w) else let (node_list, total) = aux_list (neighbours g pos) (pos::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 : unit -> 'a list * weight) (total : weight) : ('a list * weight) = let (pos, w) = node in if pos = b then (b::visited, total + w) else if List.mem pos visited then fc () else match (neighbou...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let aux (g: 'a graph) (a: 'a) (b: 'a) (init_w: weight) : ('a list * weight) option = let max = ref ([], init_w) in let find_max (path, w) = let (cur_path, cur_max) = !max in if cur_max < w then max := (path, w) else max := !max in match f...
let open_account (initial_pass: passwd) : bank_account = notimplemented () ;;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let wrong = ref 0 in let update_pass old_pass new_pass = if old_pass = !password then let _ = wrong := 0 in password := new_pass else match !wrong with | 5 -> raise wrong_pass | _ -> let _ = wrong := ((!wr...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes; edges} = g in match (nodes, edges) with | ([], []) | (_, []) | ([], _) -> [] | _ -> let choose list (v1, v2, weight) = if vertex = v1 then (v2, weight)::list else list in List.fold_left choose [] 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 (pos, w) = node in if List.mem pos visited then raise Fail else if pos = b then (pos::visited, w) else let (node_list, total) = aux_list (neighbours g pos) (pos::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 : unit -> 'a list * weight) (total : weight) : ('a list * weight) = let (pos, w) = node in if pos = b then (b::visited, total + w) else if List.mem pos visited then fc () else match (neighbou...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_max (l : ('a list * weight) list) (max : 'a list * weight) : ('a list * weight) = match l with | [] -> max | cur::remain -> let (_, cur_weight) = cur in let (_, max_weight) = max in if cur_weight > max_weight then find_max re...
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let passwd = ref initial_pass in let failure = ref 0 in let update_pass old_password new_password = if old_password <> !passwd then (failure := !failure + 1; raise wrong_pass) else (passwd := new_password;failure := 0) in let deposit passwo...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = notimplemented();;