text
stringlengths
0
601k
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 in let balance = ref 0 in let att = ref 0 in { update_pass = (fun oldp newp -> if oldp <> !password then (att := !att+1; raise wrong_pass) else att :=0; password := newp); retrieve = (fun pass amount -> if pass <> !password then (a...
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: 'a * weight) (visited : 'a list) : ('a list * weight) = let (n,w) = node in if n = b then ([n],w) else if List.mem n visited then raise Fail else let (sub_list, sub_w) = aux_list (neighbours g n) (n::visited) in (n::sub_list, w+s...
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 success1 = sc in if n = b then success1 ([n],w) else if List.mem n visited then fc () else let success2 = fun (sub_list, sub_w) -> success1 (n...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all = find_all_paths g a b in match all with | [] -> None | [p] -> Some (p) | first::rest -> Some (let f = fun (path,w) (first_path, max) -> if w > max then (path, w) else (first_path, max) in List.fold_right f all first) ;;
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let passwd = ref initial_pass in let wrong_times = ref 0 in let update_pass old_passwd new_passwd = if old_passwd = !passwd then (wrong_times := 0; passwd := new_passwd) else (incr wrong_times; raise wrong_pass) in let deposit input_passwd ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (in', out', weight) -> if in' = vertex then (out', weight)::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 node, weigth = node in if List.mem node visited then [], 0 else if node = b then [node], weigth else;;
let neighbours = neighbours g node |> List.filter (fun (x, _) -> not @@ List.mem x visited) in let l, weight' = aux_list neighbours (node :: visited) in if List.length l = 0 then [], 0 else node :: l, weight' + weigth and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = let k = List.fold_l...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) cont = let node, weigth = node in if List.mem node visited then cont ([], 0) else if node = b then cont ([node], weigth) else;;
let neighbours = neighbours g node |> List.filter (fun (x, _) -> not @@ List.mem x visited) in aux_list neighbours (node :: visited) (fun (l, weigth') -> if List.length l = 0 then cont ([], 0) else cont (node :: l, weigth' + weigth)) and aux_list (nodes: ('a * weight) list) (visited: 'a list) cont = let rec f l = match...
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) list = let node, weigth = node in if List.mem node visited then [[], 0] else if node = b then [[node], weigth] else;;
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let path = find_all_paths g a b in List.fold_left (fun acc (l, weight) -> match acc with | Some (l', weight') -> if weight >= weight' then Some (l, weight) else acc | None -> Some (l, weight) ) None path;;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let fail_cnt = ref 0 in let update_pass (old_pass:passwd) (new_pass:passwd) = if (old_pass = !password) then let _ = (fail_cnt := 0 ) in password := new_pass else (let _ =(fail_cnt := fail_cnt.contents + 1...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges v acc = match edges with | [] -> acc |(v1,v2,w) :: tl when v1 = v -> helper tl v ((v2,w) :: acc) | _ :: tl -> helper tl v 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) : ('a list * weight) = match node, visited with | (v,w) , visited when v = b -> ([],0) | (v,w) , visited when List.exists ((=) v) visited -> raise Fail | (v,w) , visited when v = a -> ( try let (...
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, visited with | (v,w) , visited when v = b -> sc ([],0) | (v,w) , visited when List.exists ((=) v) visited -> fc () | (v,w) , visited when v = a -> let sc2 ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | listOfPaths -> Some(List.fold_right (fun (ls1,w1) -> fun (ls2,w2)-> if w1>w2 then (ls1,w1) else (ls2,w2)) listOfPaths ([],0));;
let new_counter () = let counter = ref 0 in { tick = (fun () -> counter := !counter + 1; !counter); reset = (fun () -> counter := 0); };;
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let password = ref initial_pass in let fail_counter = ref 0 in { update_pass = ( fun p1 p2 -> if compare p1 !password != 0 then ( fail_counter := !fail_counter + 1; raise wrong_pass ) else ( fail_counter := 0; password := p2 ) ); retrieve =...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec rec_neighbours (edges: ('a * 'a * weight) list) (rec_vertex: 'a) out_list : ('a * weight) list = match edges with | [] -> out_list | (a,b,c)::rest -> if a = rec_vertex then rec_neighbours rest rec_vertex ((b,c)::out_list) else rec_neighbours rest ...
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) = match node with | (x,y) when x = b -> (List.rev (x::visited), acc + y) | (x,y) -> aux_list (neighbours g x) (x::visited) (acc+y) and aux_list (nodes: ('a * weight)...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) visited fc sc : ('a list * weight) = match node with | (x,y) when x = b -> ((visited [x]), sc y) | (x,y) -> aux_list (neighbours g x) (fun r -> visited (x::r)) fc (fun r -> sc (r + y)) and aux_list (nodes: ('a * wei...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = try ( Some (find_path g a b) ) with Fail -> None;;
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let acc_password = ref initial_pass in let num_of_failures = ref 0 in let check_pass (pwd : passwd) : bool = (pwd = !acc_password) in let login (pwd : passwd) (can_be_locked_out : bool) : unit = if (can_be_locked_out && !num_of_failures >= ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun curr_edge l -> match curr_edge with | (v1, v2, w) when v1 = vertex -> List.append l ((v2,w)::[]) | _ -> 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) (w_tot : int) : ('a list * weight) = match node with | (v, weight) when v = b -> (List.rev (v :: visited), w_tot + weight) | (v, weight) -> let next_nodes = (neighbours g v) in if next_nodes = [] ...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (node: 'a * weight) (visited : 'a list) (fc : unit -> 'b) (sc : 'a list -> weight -> 'a list * weight) = let (v, _) = node in let next_nodes = List.filter (fun (n : 'a * weight) -> let (value, _) = n in not (List.mem value visited)) (n...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec aux_rec (options : ('a list * weight) list) (biggest_weight : int) (biggest_path : ('a list * weight)) : ('a list * weight) = match options with | [] -> biggest_path | hd::tl -> (let (_, curr_weight) = hd in if (curr_weight > bigg...
let open_account (initial_pass: passwd) : bank_account = let pwd = ref initial_pass in let balance = ref 0 in let fld_attempts = ref 0 in let update_pass (x:passwd) (y:passwd) = if x=pwd.contents then (fld_attempts:= 0;pwd := y) else (fld_attempts:=fld_attempts.contents + 1;raise wrong_pass) in let deposit (x:passwd) (...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec edig (edg: ('a * 'a * weight) list) (v: 'a) = match edg with | [] -> [] | (vertex,u,k)::tl when vertex=v -> (u,k)::edig tl v | (vertex,u,k)::tl -> edig tl v in edig 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) = match node,visited with | (x,u),visited when x=b -> ([b],u) | (x,u),visited when x=a && not (List.exists (fun elm -> elm=a) visited) -> (try let (l,w) =aux_list (neighbours ...
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,visited with | (x,u),visited when x=b -> sc ([b],u) | (x,u),visited when x=a && not (List.exists (fun elm -> elm=a) visited) -> (let sc_tl=(fun (l,w)->sc (a...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match (find_all_paths g a b) with | [] -> None | x::xs -> Some(List.fold_left (fun (c,d)-> fun (h,i)-> if d>i then (c,d) else (h,i)) x xs);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass and account_balance = ref 0 and wrong_attempts = ref 0 in { update_pass = (fun (old_pw: passwd) (new_pw: passwd) -> if old_pw = !password then (password := new_pw; wrong_attempts := 0) else (wrong_attempts := !wrong_attempts + 1; r...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1, v2, w) -> 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): '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 (path, cost) = aux_list (neighbours g node) (node :: visited) in (node :: path, w + cos...
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 aux_list (neighbours g node) (node :: visited) fc (fun (path, cost) -> sc(node :: path,...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(path,w)] -> Some(path,w) | (path1,w1) :: (path2,w2) :: rest -> if w1 >= w2 then max ((path1,w1) :: rest) else max ((path2,w2) :: rest) in max (find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass and account_balance = ref 0 and wrong_attempts = ref 0 in { update_pass = (fun (old_pw: passwd) (new_pw: passwd) -> if old_pw = !password then (password := new_pw; wrong_attempts := 0) else (wrong_attempts := !wrong_attempts + 1; r...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1, v2, w) -> 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): '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 (path, cost) = aux_list (neighbours g node) (node :: visited) in (node :: path, w + cos...
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 aux_list (neighbours g node) (node :: visited) fc (fun (path, cost) -> sc(node :: path,...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(path,cost)] -> Some(path,cost) | (path1,cost1) :: (path2,cost2) :: rest -> if cost1 >= cost2 then max ((path1,cost1) :: rest) else max ((path2, cost2) :: rest) in max (find_all_paths g a b);;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let curr_balance = ref 0 in let fail_attempts = ref 0 in { update_pass = (fun old_pw new_pw -> if !fail_attempts > 4 then begin if !password = old_pw then begin password := new_pw; fail_attempts := 0; end else raise wrong_pass e...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge lst (s, t, w) = if s = vertex then (t,w) :: lst else lst in List.fold_left edge [] 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) (cost: int) : ('a list * weight) = let (n,w) = node in if n = b then (visited, w) else let neighbour_set = neighbours g n in if List.exists (fun x -> x = n) visited then aux_list [] visited cost e...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (cost: int) fc sc : ('a list * weight)= let (n,w) = node in if n = b then sc (visited, w) else let neighbour_set = neighbours g n in if List.exists (fun x -> x = n) visited then aux_list [] visit...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max = ref 0 in let result = ref ([],0) in let rec find_max paths = match paths with [] -> None | (l,w) :: [] -> if w > !max then Some (l,w) else Some !result | (l,w) :: xs -> if w > !max then begin max := w; result := (l,w); find_max ...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let curr_bal = ref 0 in let counter = ref 0 in { update_pass = (fun initial_pass new_pass -> if (initial_pass = !password) then (password := new_pass; counter := 0) else (counter := (!counter + 1); raise (wrong_pass))); deposit ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun l (v1, v2, w) -> if (v1 = vertex) then (v2, w)::l else l) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let weigh = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (x,y) = node in if (x=b) then (List.rev (x::visited), (!weigh + y)) else ((weigh := !weigh + y); aux_list (neighbours g x) (x::visited)) 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) fc sc : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in aux_list (neighbours g a) [a] (raise Fa...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths (g: 'a graph) (a: 'a) (b: 'a) in let [] = all_paths in None;;
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let curr_bal = ref 0 in let counter = ref 0 in { update_pass = (fun initial_pass new_pass -> if (initial_pass = !password) then (password := new_pass; counter := 0) else (counter := (!counter + 1); raise (wrong_pass))); deposit ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun l (v1, v2, w) -> if (v1 = vertex) then (v2, w)::l else l) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let weigh = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (x,y) = node in if (x=b) then (List.rev (x::visited), (!weigh + y)) else ((weigh := !weigh + y); aux_list (neighbours g x) (x::visited)) and aux_lis...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let weigh = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (x,y) = node in if (x=b) then (List.rev (x::visited), (!weigh + y)) else ((weigh := !weigh + y); aux_list (neighbours g x) (x::visited) (raise...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths (g: 'a graph) (a: 'a) (b: 'a) in let [] = all_paths in None;;
let open_account (pass : string) : bank_account = let password = ref pass in let balance = ref 0 in let wrong_pass_counter = ref 0 in { update_pass = (fun pass pass1 -> if pass = !password then begin password := pass1; wrong_pass_counter := 0 end else begin incr wrong_pass_counter; raise wrong_pass end ); retrieve = (f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1, v2, w) -> if v1 = vertex then (v2, w) :: acc else acc) [] (List.rev 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 nghb = neighbours g (fst node) in let nghb_upd = List.fold_left (fun acc (v, w) -> if List.mem v visited then acc else acc @ [(v, w + (snd node))]) [] nghb in aux_list n...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (fc : 'a list) (sc : weight): ('a list * weight) = let nghb = neighbours g (fst node) in let nghb_upd = List.filter (fun (v,w) -> not (List.mem v visited)) nghb in aux_list nghb_upd (fst node :: ...
let find_longest_path (g : 'a graph) (a : 'a) (b : 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | lps -> List.fold_left (fun acc (lp, w) -> begin match acc with | None -> Some (lp, w) | Some (_, w_acc) -> if w > w_acc then Some (lp,w) else acc end) None lps ;;
let open_account (pass : string) : bank_account = let password = ref pass in let balance = ref 0 in let wrong_pass_counter = ref 0 in { update_pass = (fun pass pass1 -> if pass = !password then begin password := pass1; wrong_pass_counter := 0 end else begin incr wrong_pass_counter; raise wrong_pass end ); retrieve = (f...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1, v2, w) -> if v1 = vertex then (v2, w) :: acc else acc) [] (List.rev 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 nghb = neighbours g (fst node) in let nghb_upd = List.fold_left (fun acc (v, w) -> if List.mem v visited then acc else acc @ [(v, w + (snd node))]) [] nghb in aux_list n...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (fc : 'a list) (sc : weight): ('a list * weight) = let nghb = neighbours g (fst node) in let nghb_upd = List.filter (fun (v,w) -> not (List.mem v visited)) nghb in aux_list nghb_upd (fst node :: ...
let find_longest_path (g : 'a graph) (a : 'a) (b : 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | lps -> List.fold_left (fun acc (lp, w) -> begin match acc with | None -> Some (lp, w) | Some (_, w_acc) -> if w > w_acc then Some (lp,w) else acc end) None lps ;;
let open_account (initial_pass: passwd) : bank_account = let pass=ref initial_pass and balance=ref 0 and failCount= ref 0 in { update_pass=(fun (p:passwd)(n:passwd) -> if(p=(!pass)) then ( failCount:=0; pass:=n ) else ( failCount:=(!failCount)+1; raise wrong_pass) ); retrieve=(fun (p:passwd)(amount:int)-> if((!failCoun...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec addNode (filter_l:('a * 'a * weight) list)(result:('a * weight) list):('a * weight) list= match filter_l with |[]-> result |x::xs-> let (_,e,n) = x in addNode (xs) ((e,n)::result) in addNode (List.filter (containNode vertex) (g.edges)) [] ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec dfs (n: ('a * weight) list) (path:'a list * weight)(visited : 'a list): ('a list * weight) = if(List.length n=0) then raise Fail else if(List.exists (fun(a:'a)-> a=(fst(List.hd n))) visited) then dfs (List.tl n) path visited else try match List....
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec dfs (n: ('a * weight) list) (path:'a list * weight)(visited : 'a list): ('a list * weight) = if(List.length n=0) then raise Fail else if(List.exists (fun(a:'a)-> a=(fst(List.hd n))) visited) then dfs (List.tl n) path visited else try match List...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l=find_all_paths g a b in if(List.length l=0)then None else let rec long_path (l:('a list * weight) list) (current:('a list * weight)):('a list * weight)option= match l with |[]->Some(current) |x::xs->if(snd(x)>snd(current)) then long...
let open_account (initial_pass: passwd) : bank_account = let old_password = ref initial_pass in let balance = ref 0 in let wrongpasscount = ref 0. in let update (initpass : passwd) (newpass : passwd) = if initpass <> !old_password then let _ = (wrongpasscount := !wrongpasscount +. 1.) in raise wrong_pass else let _ = (...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec getNodes (theList : ('a * 'a * weight) list) (thing :'a) : ('a * weight) list = match theList with | [] -> [] | c :: d -> let (f, g, w) = c in if f = thing then [(g, w)] @ getNodes d thing else getNodes d thing in getNodes g.edges vertex ;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let ret = ref [a] in let rec popList nod visit = if List.mem nod visit then if !ret = [] then raise Fail else if List.hd (List.rev !ret) = nod then let _ = ret := List.rev (List.tl (List.rev !ret)) in if !ret = [] then raise Fail else popList (List.hd (...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let ret = ref [a] in let rec popList nod visit = if List.mem nod visit then if !ret = [] then raise Fail else if List.hd (List.rev !ret) = nod then let _ = ret := List.rev (List.tl (List.rev !ret)) in if !ret = [] then raise Fail else popList (List.hd ...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec getLongest num longestPath lis = match lis with |[] -> if longestPath = ([], 0) then None else Some longestPath |a :: b -> let (l, p) = a in if p > num then getLongest p (l, p) b else getLongest num longestPath b in getLongest 0 (...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let pass_attempts = ref 0 in let balance = ref 0 in let validate_pass pass = if !pass_attempts >= 5 then raise too_many_failures else if !password = pass then pass_attempts := 0 else (pass_attempts := !pass_attempts + 1; raise w...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun l (from, to_, w) -> if from = vertex then (to_, w) :: l else l ) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec impl (nodes: ('a * weight) list) (path: 'a list) (w: weight) : ('a list * weight) = if (List.hd path) = b then (List.rev path, w) else match nodes with | [] -> raise Fail | ((e, ew)::rs) -> if List.mem e path then impl rs path w else try impl (n...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec impl (nodes: ('a * weight) list) (path: 'a list) (w: weight) (failure: unit -> ('a list * weight)) : ('a list * weight) = if (List.hd path) = b then (List.rev path, w) else match nodes with | [] -> failure () | ((e, ew)::rs) -> if List.mem e pa...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = List.fold_left ( fun path_a (pb, wb) -> match path_a with | None -> Some (pb, wb) | Some (pa, wa) -> if wa > wb then Some (pa, wa) else Some (pb, wb) ) None (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 fails = ref 0 in let validate (pass : passwd): bool = ( if (pass = !password) then (fails := 0; true) else (fails := !fails + 1; false) ) in { update_pass = (fun pass -> fun npass -> if (validate pass)...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let from_vertex = fun (v :'a) -> fun ((v1, _, _):('a * 'a * weight)) -> v = v1 in let out = fun ((_, v2, w) : ('a * 'a * weight)) -> (v2, w) in let valid_edges = List.filter (from_vertex vertex) g.edges in List.map out valid_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 (v, w) = node in if (List.mem v visited) then raise Fail else if (v = b) then (visited @ [v], acc+w) else aux_list (neighbours g v) (visited @ [v]) (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) acc fc sc : ('a list * weight)= let (v, w) = node in if (v = b) then sc node (visited, acc) else if (List.mem v visited) then fc () else aux_list (neighbours g v) (visited @ [v]) (acc+w) fc sc an...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in match paths with | [] -> None | _ -> let rec get_max (list : ('a list * weight) list) max = match list with | [] -> max | x :: xs -> if ((snd x) > (snd max)) then get_max xs (x) else get_max xs max in S...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let attempts = ref 0 in let storage = ref 0 in { update_pass = (fun first second -> if !password <> first then( attempts := !attempts + 1; raise wrong_pass) else( password := second; attempts := 0)); retrieve = (fun pass amount ...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec aux (lst1 : ('a * 'a * weight) list) (lst2 : ('a * weight) list) = match lst1 with | [] -> lst2 | x::xs -> if getFirst x = vertex then aux xs ((getSecond x, getThird x)::lst2) else aux xs lst2 in aux 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) (path: 'a list): ('a list * weight) = if (fst node) = b then (path@[b], w + (snd node)) else (if (List.filter (fun a -> a = (fst node)) visited) = [] then aux_list g.edges (visited@[(f...
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node fail (node: 'a * weight) (visited : 'a list) (w: weight) (path: 'a list): ('a list * weight) = if (fst node) = b then (path@[b], w + (snd node)) else (if (List.filter (fun a -> a = (fst node)) visited) = [] then aux_list fail g.edges (...
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec search paths max state = if (state = "first" && paths = []) then None else match paths with | [] -> Some max | x::xs -> if ((snd x) > (snd max)) then (let max = x in search xs max "no") else search xs max "no" in let paths = find_...
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let counter = ref 0 in let balance = ref 0 in {update_pass = (fun p1 p2 -> if p1 = !password then (counter := 0; password := p2) else (counter := !counter +1;raise wrong_pass)); retrieve = (fun p amount -> if !counter > 4 then r...
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc x -> let (a,b,c) = x in if a = vertex then (b,c)::acc else acc) [] g.edges;;
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec total_weight (result : ('a * weight) list): int = match result with | [] -> 0 | x::xs -> snd x + total_weight xs in let rec nodes_to_list (result : ('a * weight) list): 'a list = match result with | [] -> [] |(a,b)::xs -> a::nodes_to_list xs in ...