text
stringlengths
0
601k
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec compare_weights paths max = match paths with | [] -> Some max | p :: ps -> let (_, w1) = p in let (_, w2) = max in if w1 > w2 then compare_weights ps p else compare_weights ps max in if a = b then None else let paths = find_all_pa...
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let bal = ref 0 in let mistypes = ref 0 in { update_pass = (fun (pswd:passwd) (newp:passwd) -> if (pswd = !pass) then (pass := newp; mistypes := 0) else (mistypes := !mistypes + 1; raise wrong_pass)); retrieve = (fun (pswd:passwd) (...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges1 = (List.filter (fun (a: (string * string * weight)) -> match a with |(y,_,_) -> if (vertex=y) then true else false |_-> false) g.edges) in List.map (fun (e,b,c) -> (b,c)) edges1 ;; let rec find_neighbour nbrs b : int = match nbrs with x::xs -> ...
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 nn = (let n = (match node with |(n,w) -> n) in (neighbours g n )) in match node with |(n,w)-> if (n=b) then (List.rev (n::visited),w) else (aux_list nn (n::visited)) and...
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 nn = (let n = (match node with |(n,w) -> n) in (neighbours g n )) in match node with |(n,w)-> if (n=b) then sc (List.rev (n::visited),w) else (aux_list nn (n::visi...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let y = find_all_paths g a b in match y with |[] -> None |(l,w)::xs -> Some(l,w);;
let open_account (initial_pass: passwd) : bank_account = let amount = ref 0 in let wrongCounter = ref 0 in let pw = ref initial_pass in let update_pass password npw = if (password = !pw) then (pw := npw; wrongCounter := 0) else (wrongCounter := (!wrongCounter+1); raise wrong_pass) in let retrieve password retrAmount = ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun x -> let (x,y,z) = x in (y,z)) (List.filter (fun x -> let (v,x,y) = x in v=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) (w:weight): ('a list * weight) = let (x,y) = node in if x = b then (((@) visited (x::[])), (y+w)) else (if (List.mem x visited) then (raise Fail) else (aux_list (neighbours g x) ((@) visited (x::[...
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 (x,y) = node in if x = b then ( sc ((@) visited (x::[])), (y+w)) else (if (List.mem x visited) then (fc ()) else (aux_list (neighbours g x) ((@) visited (x::[]))...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (l: ('a list * weight) list) currMax currMaxW : ('a list * weight) = match l with |h::t -> (let (x,y) = h in if y > currMaxW then helper t h y else helper t currMax currMaxW ) |[] -> currMax in let result = find_all_paths g...
let open_account (initial_pass: passwd) : bank_account = let local_pass = ref initial_pass in let local_balance = ref 0 in let pass_counter = ref 0 in {update_pass = (fun attemptP newP -> if attemptP = !local_pass then (pass_counter := 0; local_pass := newP) else (pass_counter := !pass_counter + 1; raise wrong_pass)); ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun e -> let (a,c,w) = e in (c,w)) (List.filter (fun edge -> let (a,c,w) = edge in a = 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) (sum : int) : ('a list * weight) = let (v,w) = node in if v = b then (visited @ [v], sum+w) else if List.exists (fun n -> n = 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) (sum: int) fc sc : ('a list * weight)= let (v,w) = node in if v = b then sc ((visited @ [v]), (sum+w)) else if List.exists (fun n -> n = v) visited then fc () else aux_list (neighbours g v) (visi...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest paths max_path max_weight = match paths with | [] -> Some (max_path, max_weight) | (v,w)::t -> if w > max_weight then longest t v w else longest t max_path max_weight in let paths = find_all_paths g a b in match paths with...
let open_account (initial_pass: passwd) : bank_account = let pwReference = ref initial_pass in let numOfErrors = ref 0 in let balance = ref 0 in let passwdChecker inputPw = if !numOfErrors > 5 then raise too_many_failures else let storedPw = !pwReference in if inputPw = storedPw then numOfErrors := 0 else (incr numOfEr...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge l (b, c, w) = if b = vertex then (c, w) :: l else l in List.fold_left edge [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([a], 0) else let rec aux_node node visited cumul : ('a list * weight) = match neighbours g node with | [] -> raise Fail | _ -> aux_list (neighbours g node) visited cumul and aux_list nodes visited cumul : ('a list * weight) = match nodes ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([a], 0) else let rec aux_node node visited cumul fc sc : ('a list * weight)= match neighbours g node with | [] -> fc () | _ -> aux_list (neighbours g node) visited cumul fc sc and aux_list nodes visited cumul fc sc : ('a list * weight) =...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let find_max max aNode = let (_, wOne), (_, wTwo) = aNode, max in if wOne > wTwo then aNode else max in match find_all_paths g a b with | [] -> None | h::t -> Some (List.fold_left find_max h t);;
let open_account (initial_pass: passwd) : bank_account = let x : int ref = ref 0 in let p : passwd ref = ref initial_pass in let fails : int ref = ref 0 in { update_pass = (fun a b -> if (a= (!p)) then (p:=b) else (raise wrong_pass fails := !fails + 1) ); retrieve = (fun a b -> if (!fails>=6) then (raise too_many_failu...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun acc edge -> let (v1, v2, w) = edge in if v1 = vertex 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) : ('a list * weight) = let aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = if not (List.mem nodes visited) then begin b node; let s = neighbours g nodes in Lis...
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) list = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) list = 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 x : int ref = ref 0 in let p : passwd ref = ref initial_pass in let fails : int ref = ref 0 in { update_pass = (fun a b -> if (a= (!p)) then (p:=b) else (raise wrong_pass fails := !fails + 1) ); retrieve = (fun a b -> if (!fails>=6) then (raise too_many_failu...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun acc edge -> let (v1, v2, w) = edge in if v1 = vertex then (v2, w)::acc else acc ) [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let result = ref 0 in let rec succNode (neighbour: ('a * weight)list) (visited: 'a list) : ('a * weight) list = List.filter (fun (n, w) -> not (List.mem n visited)) neighbour in let rec finder (travelled_list: ('a *weight) list) (visited: 'a list) (this...
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) list = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) list = 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 x : int ref = ref 0 in let p : passwd ref = ref initial_pass in let fails : int ref = ref 0 in { update_pass = (fun a b -> if (a= (!p)) then (p:=b) else (raise wrong_pass fails := !fails + 1) ); retrieve = (fun a b -> if (!fails>=6) then (raise too_many_failu...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun acc edge -> let (v1, v2, w) = edge in if v1 = vertex then (v2, w)::acc else acc ) [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let result = ref 0 in let rec succNode (neighbour: ('a * weight)list) (visited: 'a list) : ('a * weight) list = List.find_all (fun (n, w) -> not (List.mem n visited)) neighbour in let rec finder (travelled_list: ('a *weight) list) (visited: 'a list) (th...
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) list = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) list = 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 x : int ref = ref 0 in let p : passwd ref = ref initial_pass in let fails : int ref = ref 0 in { update_pass = (fun a b -> if (a= (!p)) then (p:=b) else (raise wrong_pass fails := !fails + 1) ); retrieve = (fun a b -> if (!fails>=6) then (raise too_many_failu...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun acc edge -> let (v1, v2, w) = edge in if v1 = vertex then (v2, w)::acc else acc ) [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let result = ref 0 in let rec succNode (neighbour: ('a * weight)list) (visited: 'a list) : ('a * weight) list = List.find_all (fun (n, w) -> not (List.memq n visited)) neighbour in let rec finder (travelled_list: ('a *weight) list) (visited: 'a list) (t...
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) list = notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) list = 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 bal = ref 0 in let pass = ref initial_pass in let failures = ref 0 in { update_pass = ( fun oldpass newpass -> if oldpass = !pass then (pass:=newpass; failures:=0) else (failures:=(!failures+1); raise wrong_pass) ); retrieve = ( fun passwd amt -> if !failures...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let add_to_list l (v1,v2,w) = if v1=vertex then (v2,w)::l else l in List.fold_left add_to_list [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let path=ref [a] in let w=ref 0 in let weights=ref [0] in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (cur,weight)=node in path:=!path@[cur]; w:=(!w+weight); weights:=weight::!weights; if cur=b then (!path,!w) els...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a=b then ([a],0) else ( let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc path cost: ('a list * weight)= let (cur,weight) = node in if List.mem cur visited then fc() else if cur=b then sc (path@[cur],cost+weight) else aux_list (neighbou...
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_cost=ref 0 in let rec helper list answer = match list with | [] -> answer | (path,cost)::ls when cost>(!max_cost) -> max_cost:=cost; helper ls (Some(path,cost)) | x::ls -> helper ls answer in help...
let open_account (initial_pass: passwd) : bank_account = let currpw = ref initial_pass in let tries = ref 0 in let balance = ref 0 in { update_pass = (fun pw newpw -> match pw = !currpw with | true -> tries := 0; currpw := newpw | false -> tries := (!tries + 1); raise wrong_pass); retrieve = (fun pw amount -> if !tries...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let prune l (v1,v2,w) = if vertex = v1 then (v2,w) :: l else l in List.fold_left prune [] g.edges ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let tally l = let rec aux acc = function | [] -> acc | (v,w)::r -> let (v',w') = acc in aux (v::v',w+w') r in aux ([],0) l in let rec aux_node (node: 'a * weight) (visited : ('a * weight) list) : ('a list * weight) = let (v,_) = node in if v = b then ta...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let tally l = let rec aux acc = function | [] -> acc | (v,w)::r -> let (v',w') = acc in aux (v::v',w+w') r in aux ([],0) l in let rec aux_node (node: 'a * weight) (visited : ('a * weight) list) : ('a list * weight) = let (v,_) = node in if v = b then t...
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 current_balance = ref 0 in let current_password = ref initial_pass in let counter = ref 0 in { update_pass = (fun old_pass -> fun new_pass -> if old_pass = !current_password then (current_password := new_pass; counter := 0) else (counter := !counter + 1; rais...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = get_out_nodes vertex g.edges [];;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node,w) visited = if node = b then ([b], w) else if not (List.mem node visited) then let (p,c) = aux_list (neighbours g node) (node :: visited) in (node :: p, c + w) else raise Fail and aux_list (nodes: ('a * weight) list) (visited: 'a...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node,w) (visited : 'a list) fc sc : ('a list * weight)= if node = b then sc ([b], w) else if not (List.mem node visited) then aux_list (neighbours g node) (node :: visited) fc (fun (n, weight) -> sc ((node :: n), (weight + w))) else f...
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 |x::xs -> Some (highest_weight x xs);;
let open_account (initial_pass: passwd) : bank_account = let counter = ref 0 in let curr_pass = ref initial_pass in let amt_curr = ref 0 in let check_failure () = if !counter >= 5 then raise too_many_failures in let check_right past_pass = if !curr_pass = past_pass then (counter := 0) else (counter := !counter + 1; rai...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right(fun (v1,v2,w) acc -> if v1 = vertex 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,w) (visited : 'a list) : ('a list * weight) = if node = b then ([b] , w) else if List.mem node visited then raise Fail else (let (path , cost) = aux_list (neighbours g node) (node :: visited) in (node :: path, cost + w)) and aux_l...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node,w) (visited : 'a list) fc sc : ('a list * weight)= if node = b then sc ([b], w) else if List.mem node visited then fc () else aux_list (neighbours g node) (node :: visited) fc (fun (path, cost) -> sc (node :: path, cost + w)) and...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(p,w)] -> Some (p,w) | (p1,w1)::(p2,w2)::t -> if w1 >= w2 then max ((p1,w1)::t) else max ((p2,w2)::t) in max(find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let counter = ref 0 in let curr_pass = ref initial_pass in let amt_curr = ref 0 in let check_failure () = if !counter >= 5 then raise too_many_failures in let check_right past_pass = if !curr_pass = past_pass then (counter := 0) else (counter := !counter + 1; rai...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right(fun (v1,v2,w) acc -> if v1 = vertex 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,w) (visited : 'a list) : ('a list * weight) = if node = b then ([b] , w) else if List.mem node visited then raise Fail else (let (path , cost) = aux_list (neighbours g node) (node :: visited) in (node :: path, cost + w)) and aux_l...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node,w) (visited : 'a list) fc sc : ('a list * weight)= if node = b then sc ([b], w) else if List.mem node visited then fc () else aux_list (neighbours g node) (node :: visited) fc (fun (path, cost) -> sc (node :: path, cost + w)) and...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(p,w)] -> Some (p,w) | (p1,w1)::(p2,w2)::t -> if w1 >= w2 then max ((p1,w1)::t) else max ((p2,w2)::t) in max(find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let counter = ref 0 in let balance = ref 0 in let pasword = ref initial_pass in {update_pass = (fun oldpass newpass -> if !pasword = oldpass then (pasword := newpass; counter := 0) else (counter := !counter + 1; raise wrong_pass)) ; retrieve = (fun pass amount ->...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (function (vertex, a, weight) -> (a,weight)) (List.filter (function (a, _,_) -> a = 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) (total:int) : ('a list * weight)= match (neighbours g (fst(node))) with |[] -> raise Fail | hd::tl -> if List.mem (fst(hd)) visited then aux_list tl visited total else if b=fst(hd) then (List.rev ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total:int) fc sc: ('a list * weight)= match (neighbours g (fst(node))) with |[] -> fc () | hd::tl -> if List.mem (fst(hd)) visited then fc () else if b=fst(hd) then sc hd visited total else aux_...
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 balance = ref 0 in let pasword = ref initial_pass in {update_pass = (fun oldpass newpass -> if !pasword = oldpass then (pasword := newpass; counter := 0) else (counter := !counter + 1; raise wrong_pass)) ; retrieve = (fun pass amount ->...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (function (vertex, a, weight) -> (a,weight)) (List.filter (function (a, _,_) -> a = 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) (total:int) : ('a list * weight)= match (neighbours g (fst(node))) with |[] -> raise Fail | hd::tl -> if List.mem (fst(hd)) visited then aux_list tl visited total else if b=fst(hd) then (List.rev ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total:int) fc sc: ('a list * weight)= match (neighbours g (fst(node))) with |[] -> fc () | hd::tl -> if List.mem (fst(hd)) visited then fc () else if b=fst(hd) then sc hd visited total else aux_...
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 balance = ref 0 in let pasword = ref initial_pass in {update_pass = (fun oldpass newpass -> if !pasword = oldpass then (pasword := newpass; counter := 0) else (counter := !counter + 1; raise wrong_pass)) ; retrieve = (fun pass amount ->...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (function (vertex, a, weight) -> (a,weight)) (List.filter (function (a, _,_) -> a = 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) (total:int) : ('a list * weight)= match (neighbours g (fst(node))) with |[] -> raise Fail | hd::tl -> if List.mem (fst(hd)) visited then aux_list tl visited total else if b=fst(hd) then (List.rev ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total:int) fc sc: ('a list * weight)= match (neighbours g (fst(node))) with |[] -> fc () | hd::tl -> if List.mem (fst(hd)) visited then fc () else if b=fst(hd) then sc hd visited total else aux_...
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::[]-> Some hd |hd :: tl ->Some (List.fold_right (fun (a,b) (c,d) -> if d >= b then (c,d) else (a,b)) (find_all_paths g a b) (hd));;
let open_account (initial_pass: passwd) : bank_account = let counter = ref 0 in let balance = ref 0 in let pasword = ref initial_pass in {update_pass = (fun oldpass newpass -> if !pasword = oldpass then (pasword := newpass; counter := 0) else (counter := !counter + 1; raise wrong_pass)) ; retrieve = (fun pass amount ->...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (function (vertex, a, weight) -> (a,weight)) (List.filter (function (a, _,_) -> a = 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) (total:int) : ('a list * weight)= match (neighbours g (fst(node))) with |[] -> raise Fail | hd::tl -> if List.mem (fst(hd)) visited then aux_list tl visited total else if b=fst(hd) then (List.rev ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total:int) fc sc: ('a list * weight)= match (neighbours g (fst(node))) with |[] -> fc () | hd::tl -> if List.mem (fst(hd)) visited then aux_list tl visited total fc sc else if b=fst(hd) then sc ...
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::[]-> Some hd |hd :: tl ->Some (List.fold_right (fun (a,b) (c,d) -> if d >= b then (c,d) else (a,b)) (find_all_paths g a b) (hd));;
let open_account (initial_pass: passwd) : bank_account = let cur_pass = ref initial_pass in let balance = ref 0 in let count = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if !cur_pass = old_pass then begin count := 0; cur_pass := new_pass end else begin count := !count + 1; raise wrong_pass e...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (rem_vert) (List.filter (fun x -> out_vert_comp 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) : ('a list * weight) = let (x,y) = node in if List.mem x visited then raise Fail else if x = b then (visited@[x], (y)) else aux_list (List.map (weight_add y) (neighbours g x)) (visited@[x]) and au...
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 = Some (find_path g a b);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let lock_account pa = if pa = !password && !counter < 5 then counter :=0 else if !counter >= 5 then raise too_many_failures else if (pa <> !password) then ( if (!counter < 5) then (c...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec newform edge acc = match edge with |[] -> acc |x::xs -> let (a,l,m) = x in if a = vertex then newform xs ((l,m)::acc) else newform xs (acc) in newform (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 * weight) list = 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 stored_pass = ref initial_pass in let balance = ref 0 in let error_counter = ref 0 in let validation pass = if !error_counter = 5 then raise too_many_failures else if pass = !stored_pass then error_counter := 0 else( error_counter := !error_counter +1; raise ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun ls edge -> let (n1,n2,w) = edge in if n1 = vertex then (n2, w)::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) = let (curr_node, w) = node in if List.exists (fun n -> n = curr_node) visited then raise Fail else if curr_node = b then ( visited@[curr_node], 0) else 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 (curr_node, w) = node in if List.exists (fun n -> n = curr_node) visited then fc () else if curr_node = b then sc ([curr_node], w) else aux_list (neighbours g curr...