text stringlengths 0 601k |
|---|
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... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let x = find_all_paths g a b in let rec max_length current_max current_path tuples_list = match tuples_list with [] -> Some (current_path, current_max) |(s, i)::tl -> if i > current_max then max_length i s tl else max_length current_max c... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let no_tries = ref 0 in let pwd = ref initial_pass in let checker funct arg pass = if (!pwd = pass) then ( no_tries := 0 ; funct arg) else ( no_tries := !no_tries + 1 ; raise wrong_pass) in let op_check (funct : 'a -> 'b) amt = if (!no_trie... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (ngb vertex) [] g.edges ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, n_weight): 'a * weight) (visited : 'a list) w (path : 'a list) : ('a list * weight) = if (node = b) then (List.rev (node :: path), (w + n_weight)) else if (List.exists ((=) node ) visited) then raise Fail else ( aux_list (neighb... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, n_weight): '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 = let rec longest paths ((max_path, max_weight) : 'a list * weight) = match paths with | [] -> Some (max_path, max_weight) | (path, wgt) :: xs -> if (wgt > max_weight) then longest xs (path, wgt) else longest xs (max_path, wgt) in let all_p... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let no_tries = ref 0 in let pwd = ref initial_pass in let checker funct arg pass = if (!pwd = pass) then ( no_tries := 0 ; funct arg) else ( no_tries := !no_tries + 1 ; raise wrong_pass) in let op_check (funct : 'a -> 'b) amt = if (!no_trie... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (ngb vertex) [] g.edges ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, n_weight): 'a * weight) (visited : 'a list) w (path : 'a list) : ('a list * weight) = if (node = b) then (List.rev (node :: path), (w + n_weight)) else if (List.exists ((=) node ) visited) then raise Fail else ( aux_list (neighb... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, n_weight): '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 = let rec longest paths ((max_path, max_weight) : 'a list * weight) = match paths with | [] -> Some (max_path, max_weight) | (path, wgt) :: xs -> if (wgt > max_weight) then longest xs (path, wgt) else longest xs (max_path, wgt) in let all_p... |
let open_account (initial_pass: passwd) : bank_account = let amount = ref 0 in let failures = ref 0 in let cur_passwd = ref (initial_pass) in { update_pass = (fun (old_pw: passwd) (new_pw: passwd) -> if old_pw = !cur_passwd then (failures:=0; cur_passwd := new_pw) else (failures:=!failures+1;raise wrong_pass) ; ); retr... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let list = (let f1 x = match x with |(a,_,_) when a = vertex ->true |_->false in List.filter f1 g.edges) in let f2 x = let (_,b,c) = x in (b, c) in List.map f2 list;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list*weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (suc: weight) : ('a list*weight) = match node with |(x,y) when x = b -> (List.rev (x::visited), suc+y) |(x,y)-> if List.mem x visited then raise Fail else let list = neighbours g x in aux_list 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)= match node with |(x,y) when x = b -> sc ([x],y) |(x,y) -> if List.mem x visited then fc () else aux_list (neighbours g x) (x::visited) fc (fun (v,m)->sc (x::v,y+m)) an... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest_helper (l: ('a list * weight) list) (node: ('a list * weight)) (len: weight) = match l with | [] -> if len=0 then None else Some (node) |x::xs-> let (_,w)=x in if w>len then longest_helper xs x w else longest_helper xs nod... |
let makeCounter () = let localCount = ref 0 in { increase = (fun () -> incr localCount; !localCount) ; reset = (fun () -> localCount := 0) ; num = (fun () -> !localCount >= 5) } ;; |
let open_account (initial_pass: passwd) : bank_account = let lc = makeCounter () in let password = ref initial_pass in let money = ref 0 in { update_pass = ( fun old_passwd new_passwd -> if old_passwd = !password then let _ = lc.reset () in password := new_passwd else let _ = lc.increase () in raise wrong_pass ) ; retr... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in List.fold_right (fun (edge: ('a * 'a * weight)) (lst: ('a * weight) list) -> let v1, v2, w = edge in ( if v1 = vertex then (v2, w) :: lst else lst ) ) edges [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nodes_list = g.nodes in let edges = g.edges in if List.exists (fun node -> node = a) nodes_list && List.exists (fun node -> node = b) nodes_list then let rec check_for_path (edges: ('a * 'a * weight) list) (a: 'a) (b: 'a) (node_lst: 'a list * weight... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nodes_list = g.nodes in let edges = g.edges in if List.exists (fun node -> node = a) nodes_list && List.exists (fun node -> node = b) nodes_list then let rec check_for_path (edges: ('a * 'a * weight) list) (a: 'a) (b: 'a) node_lst_fxn (index: int) ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let ans = find_all_paths g a b in match ans with | [] -> None | _ -> let rec get_long_path (path_list: ('a list * weight) list) (best_ans: ('a list * weight)) : ('a list * weight) = match path_list with | [] -> best_ans | (lst, w)::rest_o... |
let makeCounter () = let counter = ref 0 in { increase = (fun () -> counter := !counter + 1) ; reset = (fun () -> counter := 0) ; get_if_locked = (fun () -> !counter >= 5) } ;; |
let open_account (initial_pass: passwd) : bank_account = let localCounter = makeCounter () in let password = ref initial_pass in let money = ref 0 in { update_pass = ( fun old_passwd new_passwd -> if old_passwd = !password then let _ = localCounter.reset () in password := new_passwd else let _ = localCounter.increase (... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in List.fold_right (fun (edge: ('a * 'a * weight)) (lst: ('a * weight) list) -> let v1, v2, w = edge in ( if v1 = vertex then (v2, w) :: lst else lst ) ) edges [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nodes_list = g.nodes in let edges = g.edges in if List.exists (fun node -> node = a) nodes_list && List.exists (fun node -> node = b) nodes_list then let rec check_for_path (edges: ('a * 'a * weight) list) (a: 'a) (b: 'a) (node_lst: 'a list * weight... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nodes_list = g.nodes in let edges = g.edges in if List.exists (fun node -> node = a) nodes_list && List.exists (fun node -> node = b) nodes_list then let rec check_for_path (edges: ('a * 'a * weight) list) (a: 'a) (b: 'a) node_lst_fxn (index: int) ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let ans = find_all_paths g a b in match ans with | [] -> None | _ -> let rec get_long_path (path_list: ('a list * weight) list) (best_ans: ('a list * weight)) : ('a list * weight) = match path_list with | [] -> best_ans | (lst, w)::rest_o... |
let makeCounter () = let counter = ref 0 in { increase = (fun () -> counter := !counter + 1) ; reset = (fun () -> counter := 0) ; get_if_locked = (fun () -> !counter >= 5) } ;; |
let open_account (initial_pass: passwd) : bank_account = let localCounter = makeCounter () in let password = ref initial_pass in let money = ref 0 in { update_pass = ( fun old_passwd new_passwd -> if old_passwd = !password then let _ = localCounter.reset () in password := new_passwd else let _ = localCounter.increase (... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in List.fold_right (fun (edge: ('a * 'a * weight)) (lst: ('a * weight) list) -> let v1, v2, w = edge in ( if v1 = vertex then (v2, w) :: lst else lst ) ) edges [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nodes_list = g.nodes in let edges = g.edges in if List.exists (fun node -> node = a) nodes_list && List.exists (fun node -> node = b) nodes_list then let rec check_for_path (edges: ('a * 'a * weight) list) (a: 'a) (b: 'a) (node_lst: 'a list * weight... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nodes_list = g.nodes in let edges = g.edges in if List.exists (fun node -> node = a) nodes_list && List.exists (fun node -> node = b) nodes_list then let rec check_for_path (edges: ('a * 'a * weight) list) (a: 'a) (b: 'a) node_lst_fxn (index: int) ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let ans = find_all_paths g a b in match ans with | [] -> None | _ -> let rec get_long_path (path_list: ('a list * weight) list) (best_ans: ('a list * weight)) : ('a list * weight) = match path_list with | [] -> best_ans | (lst, w)::rest_o... |
let open_account (initial_pass: passwd) : bank_account = let money = ref 0 in let currentPassword = ref initial_pass in let failures = ref 0 in { update_pass = (fun password newPassword -> if not(String.equal password !currentPassword) then (failures := !failures + 1; raise wrong_pass) else failures := 0; currentPasswo... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun (l: ('a * weight) list) y -> let (p,n,w) = y in if (p = vertex) then (n,w) :: l else l ) [] g.edges ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (distance : int) : ('a list * weight) = let (n,w) = node in if (n = b) then (visited @ [b], distance + w) else if (List.exists (fun x -> x = n) visited) then raise Fail 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) (distance : int) fc sc : ('a list * weight)= let (n,w) = node in if (n = b) then (visited @ [b], distance + w) else if (List.exists (fun x -> x = n) visited) then fc () else let sc2 = fun n w -> ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec path_helper (g: 'a graph) (a: 'a) (b: 'a) (allpaths: ('a list * weight) list) (max : 'a list * weight) : ('a list * weight) option = match allpaths with | [] -> None | (l,w) :: xs -> if (xs = []) then if (w > snd (max)) then Some ... |
let open_account (initial_pass: passwd) : bank_account = let failure_count = ref 0 in let balance = ref 0 in let password = ref initial_pass in { update_pass = (fun input1 input2 -> if input1 = !password then let _ = (failure_count := 0) in password := input2 else if !failure_count > 5 then raise too_many_failures else... |
let neighbours (g: 'a graph) (vertex: 'a): ('a * weight) list = let _ = g in List.fold_right (fun x y -> let (a,b,c) = x in if a = vertex then (b,c)::y else y) g.edges [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let neib = neighbours g a in let rec aux_node (node: 'a * weight) (visited : 'a list) (cur_w:weight) : ('a list * weight) = if not(List.mem (fst(node)) visited) then let visited = fst(node)::visited in let cur_w = cur_w + snd(node) in if (fst(node) = b)... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let neib = neighbours g a in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight) = if not(List.mem (fst(node)) visited) then let visited = fst(node)::visited in if (fst(node) = b) then (List.rev visited,sc (snd(node))) e... |
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_count = ref 0 in let balance = ref 0 in let password = ref initial_pass in { update_pass = (fun input1 input2 -> if input1 = !password then let _ = (failure_count := 0) in password := input2 else if !failure_count > 5 then raise too_many_failures else... |
let neighbours (g: 'a graph) (vertex: 'a): ('a * weight) list = let _ = g in List.fold_right (fun x y -> let (a,b,c) = x in if a = vertex then (b,c)::y else y) g.edges [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let neib = neighbours g a in let rec aux_node (node: 'a * weight) (visited : 'a list) (cur_w:weight) : ('a list * weight) = if not(List.mem (fst(node)) visited) then let visited = fst(node)::visited in let cur_w = cur_w + snd(node) in if (fst(node) = b)... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let neib = neighbours g a in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight) = if not(List.mem (fst(node)) visited) then let visited = fst(node)::visited in if (fst(node) = b) then (List.rev visited,sc (snd(node))) e... |
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 curr_pass = ref initial_pass in let balance = ref 0 in let attempts = ref 1 in { update_pass = (fun pass new_pass -> if pass = !curr_pass then (attempts := 1; curr_pass := new_pass) else (attempts := !attempts + 1; raise wrong_pass)); retrieve = (fun pass amt... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec get_neighbours (nl: ('a * weight) list) (edge: ('a * 'a * weight)) : ('a * weight) list = let (fn, tn, w) = edge in if vertex = fn then match nl with | [] -> (tn, w) :: [] | hd :: tl -> hd :: get_neighbours tl edge else nl in List.fold_left get_ne... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let tw = ref 0 in let nl = ref (a :: []) in let v = ref (a :: []) in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (n, w) = node in match visited with | [] -> (v := (n :: !v); nl := n :: !nl; tw := !tw + w; if n = b... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let tw = ref 0 in let nl = ref (a :: []) in let v = ref (a :: []) in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight) = let (n, w) = node in match visited with | [] -> (v := (n :: !v); nl := n :: !nl; tw := !tw + w; i... |
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 | hd :: tl -> if tl = [] then Some hd else let max = (fun x path -> let (p, w) = x in let (p', w') = path in if w' > w then (p', w') else (p, w)) in Some (List.fold_left ma... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let attempts = ref 0 in let password = ref initial_pass in { update_pass = (fun oldPwd newPwd -> if oldPwd = !password then ( attempts := 0; password := newPwd ) else ( attempts := (!attempts+1); raise wrong_pass ) ) ; retrieve = (fun pwd a... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun arr (v1, v2, w) -> if (v1 = vertex) then (v2, w)::arr else arr ) [] 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) weight : ('a list * weight) = let (n, w) = node in if (n = b) then (visited @ [n], weight+w) else ( (if (List.mem n visited) then raise Fail else aux_list (neighbours g n) (visited @ [n]) (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, w) = node in if (n = b) then sc [n] w else ( (if (List.mem n visited) then fc () else ( aux_list (neighbours g n) (visited @ [n]) (fun () -> fc ()) (fun scN s... |
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 ( Some (List.fold_right (fun (p1, w1) (p2, w2) -> if w1 > w2 then (p1, w1) else (p2, w2)) allPaths ([], 0)) );; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = (fun x y -> if x = !pass then (pass := y; attempts := 0) else (attempts := !attempts + 1; raise wrong_pass) ); retrieve = (fun x y -> if !attempts >= 5 then raise too_ma... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (x, y, w) acc -> if x = vertex then (y,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 (x,y) = node in if x = b then ([b],y) else if List.mem x visited then raise Fail else let (path,w) = (aux_list (neighbours g x) ([x]@visited)) in (x::path, w+y) and aux_... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (x,y) = node in if x = b then sc ([x],y) else if List.mem x visited then fc () else let sc2 = fun (w,z)-> sc ([x]@w, z+y) in aux_list (neighbours g x) ([x]@visited... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max (lc:('a list * weight) list) (m:'a list * weight)= match (lc,m) with |((x,y)::[], (w,v)) -> if (y>=v) then Some (x,y) else Some (w,v) |((x,y)::xs, (w,v)) -> if (y>=v) then max xs (x,y) else max xs (w,v) |_->None in max (find_a... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = (fun x y -> if x = !pass then (pass := y; attempts := 0) else (attempts := !attempts + 1; raise wrong_pass) ); retrieve = (fun x y -> if !attempts >= 5 then raise too_ma... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (x, y, w) acc -> if x = vertex then (y,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 (x,y) = node in if x = b then ([b],y) else if List.mem x visited then raise Fail else let (path,w) = (aux_list (neighbours g x) ([x]@visited)) in (x::path, w+y) and aux_... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (x,y) = node in if x = b then sc ([x],y) else if List.mem x visited then fc () else let sc2 = fun (w,z)-> sc ([x]@w, z+y) in aux_list (neighbours g x) ([x]@visited... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max (lc:('a list * weight) list) (m:'a list * weight)= match (lc,m) with |((x,y)::[], (w,v)) -> if (y>=v) then Some (x,y) else Some (w,v) |((x,y)::xs, (w,v)) -> if (y>=v) then max xs (x,y) else max xs (w,v) |_->None in max (find_a... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let attempts = ref 0 in let password = ref initial_pass in let (a:bank_account) = { update_pass = (fun (a:passwd) (b:passwd) -> ( if (a = !password) then (attempts:=0; password:=b;) else ((attempts := !attempts + 1); raise (wrong_pass); ) )... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let nodes = g.nodes in let edges = g.edges in List.fold_left ( (fun a e -> let (l,r,w) = e in if(l=vertex) then (r,w):: a else a ) ) [] 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, wgt) = node in let new_visited = visited in let nb = (neighbours g curr_node) in let notvisited = List.filter ( fun v -> let (n,w) = v in not (List.exists (f... |
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, wgt) = node in let new_visited = visited in let nb = (neighbours g curr_node) in let notvisited = List.filter ( fun v -> let (n,w) = v in not (List.exi... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let ls = find_all_paths g a b in let ls = List.sort (fun (la,a) (lb,b) -> if a<b then -1 else if a>b then 1 else 0) ls in if(ls=[]) then None else Some (let x::_ = ls in x);; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let wrong_count = ref 0 in { update_pass = (fun old_pass new_pass -> (if old_pass = !pass then (pass := new_pass; wrong_count := 0) else (wrong_count := !wrong_count + 1; raise wrong_pass))); retrieve = (fun p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec aux_nei (e: ('a * 'a * weight) list) (node: 'a) (result: ('a * weight) list): ('a * weight) list = match e with | [] -> result | (n1,n2,w)::tl -> (if n1 = node then aux_nei tl node (List.append result [(n2,w)]) else aux_nei tl node result) in aux_... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([a],0) else let rec helper (neigh: ('a * weight) list) (visited: 'a list) (path: 'a list) (tot_weight: weight): ('a list * weight)= match neigh with | [] -> raise Fail | (node,weight)::t -> (if node = b then (List.append path [node], tot_... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper (neigh: ('a * weight) list) (visited: 'a list) (path: 'a list) (tot_weight: weight) fc sc: ('a list * weight)= match neigh with | [] -> fc () | (node,weight)::t -> (if node = b then sc (node,weight) (path,tot_weight) else (if List.mem no... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (paths: ('a list * weight) list) (high_path: 'a list) (high_cost: weight): ('a list * weight) option = match paths with | [] -> (if high_path = [] then None else Some (high_path, high_cost)) | (p,w)::t -> (if w > high_cost ... |
let open_account (initial_pass : passwd) : bank_account = let password = ref initial_pass in let auth_failures = ref 0 in let balance = ref 0 in let auth_blocked = ref false in let update_pass (cur_pass : passwd) (new_pass : passwd) : unit = if cur_pass = !password then if !auth_blocked = true then ( auth_blocked := fa... |
let neighbours (g : 'a graph) (vertex : 'a) : ('a * weight) list = let f init (b : 'a * 'a * weight) = match b with | n1, n2, w -> if n1 = vertex then (n2, w) :: init else init in List.fold_left f [] g.edges ;; let rec sum lst acc : weight = match lst with | [] -> acc | h :: t -> sum t (acc + h) ;; |
let find_path (g : 'a graph) (a : 'a) (b : 'a) : 'a list * weight = let rec aux u v path visited weights moves = if u = v then List.rev (u :: path), sum weights 0 else ( match moves with | (node, w) :: t -> if List.mem node visited then aux u v path visited weights t else aux node v (u :: path) (u :: visited) (w :: wei... |
let find_path' (g : 'a graph) (a : 'a) (b : 'a) : 'a list * weight = let fail_continuation f = f in let success_continuation end_path end_weights = List.rev end_path, sum end_weights 0 in let rec aux u v path visited weights moves fc sc = if u = v then sc (u :: path) weights else ( match moves with | (node, w) :: 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 pass = ref initial_pass in let balance = ref 0 in let count = ref 0 in { update_pass = (fun input1 input2 -> let old = !pass in match String.equal input1 old with | true -> pass := input2 | _ -> raise wrong_pass) ; retrieve = (fun input1 input2 -> let pw = !p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper (e: ('a * 'a * weight) list) (vertex: 'a) : ('a * weight) list = match e with | [] -> [] | h::t -> let (s, _, w) = h in if s = vertex then (s, w)::helper t vertex else helper t vertex 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) = 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 failedAttempts = ref 0 in let balance = ref 0 in { update_pass = (fun (oldPasswd: passwd) (newPasswd: passwd) -> if !password = oldPasswd then let () = failedAttempts := 0 in password := newPasswd else let () = (failedAttemp... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f (a: 'a * 'a * weight) (l: ('a * weight) list) = let (x,y,z) = a in if x = vertex then (y,z)::l else l 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) : ('a list * weight) = let (x,wt) = node in if x = b then ([x], wt) else if List.mem x visited then raise Fail else let (l,lt) = aux_list (neighbours g x) (x::visited) in ((x::l),(wt + lt)) 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)= let (x,wt) = node in if x = b then sc [x] wt else if List.mem x visited then fc () else let sc2 = fun (y: 'a list) (lwt: weight) -> sc (x::y) (wt + lwt) in aux_list (n... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f (x: ('a list * weight)) (y: ('a list * weight)) = let (_,xw) = x in let (_,yw) = y in if xw > yw then x else y in let l = find_all_paths g a b in match l with | [] -> None | _ -> Some (List.fold_left f ([], -1) l);; |
let open_account (initial_pass: passwd) : bank_account = let cur_pwd = ref initial_pass in let balance = ref 0 in let failure_count = ref 0 in { update_pass = (fun attempted_pwd new_pwd -> if attempted_pwd = !cur_pwd then (failure_count := 0; cur_pwd := new_pwd) else if attempted_pwd <> !cur_pwd then (failure_count := ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes; edges = useful} = g in begin let rec helper useful vertex list = match useful with | [] -> list | [(v1, v2, w)] -> if v1 = vertex then helper [] vertex ((v2, w) :: list) else helper [] vertex list | [(v1, v2, w); rest] -> if v1 = vertex then h... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_weight: weight) : ('a list * weight) = let (a,weight) = node in if a = b then (List.rev (b :: visited), (total_weight + weight)) else if List.mem a visited then raise Fail else aux_list (ne... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_weight: weight) fc sc : ('a list * weight)= let (a,weight) = node in if a = b then (List.rev (b :: visited), (total_weight + weight)) else if List.mem a visited then fc () else aux_list (n... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper paths_list big_list big_weight = match paths_list with | (list, weight):: rest -> if weight > big_weight then helper rest list weight else if weight = big_weight then if List.length list > List.length big_list then helper r... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.