text stringlengths 0 601k |
|---|
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (_, v2, w) -> (v2, w)) (List.filter (fun (v1, _, _) -> v1 = vertex) g.edges);; |
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 = if (List.mem (fst node) visited) then [] else if ((fst node) = b) then [([fst node], snd node)] else List.map (fun x -> (fst node :: fst x, (snd node + snd x)... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = match (find_all_paths g a b) with | x :: xs -> x | _ -> raise Fail;; |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (List.mem (fst node) visited) then fc () else if ((fst node) = b) then sc ([fst node], snd node) else (aux_list (neighbours g (fst node)) (visited @ [fst node])) (f... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match List.rev (List.sort (fun a b -> if snd a > snd b then 1 else if snd b > snd a then -1 else 0) (find_all_paths g a b)) with | x :: xs -> Some(x) | _ -> None;; |
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let bal = ref 0 in let wrongPasswordCounter = ref 0 in {update_pass = (fun (old_pass : passwd) (new_pass : passwd) -> if old_pass = !pw then (pw := new_pass; wrongPasswordCounter := 0;) else (wrongPasswordCounter := !wrongPasswordCoun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = getNeighborsAndWeights 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) (weightAcc : weight) : ('a list * weight) = if fst(node) = b then (visited @ [fst(node)], weightAcc + snd(node)) else if List.mem (fst(node)) visited then raise Fail else aux_list (neighbours g (f... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weightAcc : weight) fc sc : ('a list * weight)= if fst(node) = b then (visited @ [fst(node)], weightAcc + snd(node)) else if List.mem (fst(node)) visited then fc() else aux_list (neighbours g (f... |
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 notimplemented();; |
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let bal = ref 0 in let wrongPasswordCounter = ref 0 in {update_pass = (fun (old_pass : passwd) (new_pass : passwd) -> if old_pass = !pw then (pw := new_pass; wrongPasswordCounter := 0;) else (wrongPasswordCounter := !wrongPasswordCoun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = getNeighborsAndWeights 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) (weightAcc : weight) : ('a list * weight) = if fst(node) = b then (visited @ [fst(node)], weightAcc + snd(node)) else if List.mem (fst(node)) visited then raise Fail else aux_list (neighbours g (f... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weightAcc : weight) fc sc : ('a list * weight)= if fst(node) = b then (visited @ [fst(node)], weightAcc + snd(node)) else if List.mem (fst(node)) visited then fc() else aux_list (neighbours g (f... |
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 firstPath = List.nth allPaths 0 in let rec findMaxWeight (currentMaxPath: 'a list * weight) (listOfPaths: ('a list * weight) list) = match listOfPaths with | [] ->... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let money = ref 0 in let fail = ref 0 in { update_pass = (fun passwd1 passwd2 -> if passwd1 <> !password then (fail := (!fail + 1); raise wrong_pass) else (password := passwd2; fail := 0)); deposit = (fun pass depo -> if !fail >... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun lst node -> let (v,x,y) = node in if vertex = v then (x,y)::lst else lst) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let path = ref [] in let all_w = ref [] in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (cur_n, cur_w) = node in path := !path @ [cur_n]; w := !w + cur_w; all_w := !all_w@[cur_w]; if b = cur_n then... |
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 (cur_n, _) = node in if b = cur_n then sc ([], 0) else aux_list (neighbours g cur_n) (cur_n::visited) fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a l... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = try Some (List.nth (List.sort (fun x y -> compare (snd y) (snd x)) (find_all_paths g a b)) 0) with Failure _ -> None;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let money = ref 0 in let fail = ref 0 in { update_pass = (fun passwd1 passwd2 -> if passwd1 <> !password then (fail := (!fail + 1); raise wrong_pass) else (password := passwd2; fail := 0)); deposit = (fun pass depo -> if !fail >... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun lst node -> let (v,x,y) = node in if vertex = v then (x,y)::lst else lst) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let path = ref [] in let all_w = ref [] in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (cur_n, cur_w) = node in path := !path @ [cur_n]; w := !w + cur_w; all_w := !all_w@[cur_w]; if b = cur_n then... |
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 (cur_n, _) = node in if b = cur_n then sc ([], 0) else aux_list (neighbours g cur_n) (cur_n::visited) fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a l... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = try Some (List.nth (List.sort (fun x y -> compare (snd y) (snd x)) (find_all_paths g a b)) 0) with Failure _ -> None;; |
let open_account (initial_pass: passwd) : bank_account = let passCount = ref 0 in let password = ref initial_pass in let balance = ref 0 in let incrCount () = passCount := !passCount + 1; raise wrong_pass in let reset () = passCount := 0 in { update_pass = (fun (input : passwd) (newPass : passwd) -> if (compare input (... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if not (List.mem vertex (g.nodes)) then [] else if (List.length g.edges = 0) then [] else let help_neighbours (edge : ('a * 'a * weight)) (ngbs : ('a * weight) list) = match edge with | (x, n, w) when (compare x vertex) = 0 -> (n, w)::ngbs | (x, _, _) whe... |
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) = match nodes with | [] -> raise Fail | hd::tl -> let (n, w) = hd in if no... |
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 = if (find_all_paths g a b) = [] then None else let rec longest (paths : ('a list * weight) list) (max : weight) (p : 'a list * weight) = match paths with | [] -> if max = 0 then None else Some(p) | (x, cur)::xs -> if cur > max then longest... |
let open_account (initial_pass: passwd) : bank_account = let max_wrong_pass = 5 in let wrong_passes = ref 0 in let password = ref initial_pass in let money = ref 0 in let too_many_failures () = if !wrong_passes >= max_wrong_pass then raise too_many_failures in let password_not_eq password' = if password' <> !password t... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.(g.edges |> filter (fun (s, _, _) -> s = vertex) |> map (fun (_, d, weight) -> d, weight));; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let invalid_value = -1 in let rec aux_node (vertex, weight: 'a * weight) (visited : 'a list) : ('a list * weight) = match vertex = b with | true -> [b], weight | _ when not (List.mem vertex visited) -> let visited = vertex :: visited in let adjs = neigh... |
let neighbours = neighbours g a in let path, path_weight = aux_list neighbours [a] in let path = if path = [] then raise Fail else a :: path in path, path_weight;; |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let invalid_value = -1 in let rec aux_node (vertex, weight: 'a * weight) (visited : 'a list) fc sc = match vertex = b with | true -> sc ([b], weight) | _ when not (List.mem vertex visited) -> let visited = vertex :: visited in let adjs = neighbours g v... |
let neighbours = neighbours g a in let fc () = raise Fail in aux_list neighbours [a] fc (fun (path, path_weight) -> if path = [] then fc () else a :: path, path_weight);; |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = List.fold_left (function | None -> fun x -> Some x | (Some (cur_list, cur_weight) as cur_path) -> function | (path_list, path_weight) when cur_weight <= path_weight -> Some (path_list, path_weight) | _ -> cur_path) None (find_all_paths g ... |
let open_account (initial_pass: passwd) : bank_account = let n = ref 0 in let pass= ref initial_pass in let balance= ref 0 in { update_pass= (fun (curpass:passwd) (newpass:passwd)-> if curpass = !pass then begin n := 0; pass := newpass end else begin n := !n+1; raise wrong_pass end ) ; retrieve=(fun inpass a -> if !n =... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if g.edges=[] then [] else if g.nodes=[] then [] else let f (p:('a * 'a * weight)) l = let (v1,v2,w)=p in if v1=vertex then let (c:int) = w in ((v2,c)::l) else l in List.fold_right f g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let n= ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (x,k)= node in if x = b then begin n:=!n + k; (visited @ [x], !n) end else if List.exists (fun y -> x=y) visited then begin n:=!n + k;raise Fail end else... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let n=ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (x,k)= node in if x = b then begin (fun (x,k) ((l:'a list), (n:weight))-> (l@[x],n+k)) end else if List.exists (fun y -> x=y) visited then begin (fu... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest list = match list with |[] -> None |(x,k)::[]-> Some (x,k) |(x,k)::(y,n)::xs -> if n>=k then longest ((y,n)::xs) else longest ((x,k)::xs) 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 failures = ref 0 in { update_pass = ( fun (old_pass: passwd) (new_pass: passwd) -> if !password = old_pass then (password := new_pass; failures := 0) else (failures := (!failures + 1); raise wrong_pass... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.rev (List.fold_left (fun acc edge -> match edge with | (v, o, weight) -> if v = vertex then (o, weight)::acc else acc | _ -> 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 (try let (l, w1) = aux_list (neighbours g n) visited in (n::l, w + w1) with Fail -> raise Fail) and aux_list (nodes: ('a *... |
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 aux_list (neighbours g n) (visited) (fun f -> fc Fail) (fun (lc, wc) -> sc (n::lc, w + wc)) and aux_list (nodes: ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let longest = ref (None : ('a list * weight) option) in let rec aux maximum l = match l with |[] -> maximum |x :: xs -> aux (max maximum x) xs in try Some (List.find (fun (l1, w1) -> w1 = (aux 0 (List.map (fun (l, w) -> w) (find_all_paths... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let count = ref 0 in let current_pass = ref initial_pass in { update_pass = (fun old_p new_p -> if (!current_pass = old_p) then (current_pass := new_p ; count := 0) else (count := (!count + 1); raise wrong_pass)); deposit = (fun pass dep ->... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = (fun(x,y,z) acc ->(y,z)::acc) in let init = [] in let a = List.filter (fun(v1,_,_) -> vertex =v1) g.edges in List.fold_right f a init let get_node = fun(v,w) -> v;; let get_weight = fun(v,w) -> w;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited:'a list) : ('a list * weight) = if (get_node node) = b then ([],0) else if List.length (neighbours g (get_node node)) = 0 then raise Fail else aux_list (neighbours g (get_node node)) ((get_node node)::(visit... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let path =([],0) in let rec aux_node (node: 'a * weight) (visited : 'a list) (path: ('a list * weight)) fc sc : ('a list * weight)= if (get_node node) = b then sc ((get_node node)::(get_node path) , (get_weight node) + (get_weight path)) else ( if List... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths g a b in if all_paths = [] then None else let f = (fun x y -> if (get_weight y) >= (get_weight x) then y else x ) in Some ( List.fold_left f ([], 0) all_paths);; |
let open_account (initial_pass: passwd) : bank_account = let pass= ref initial_pass in let wrongs= ref 0 in let balance= ref 0 in { update_pass=(fun (old:passwd) (nu:passwd) -> if (old = !pass) then let _ = wrongs:=0 in pass := nu else let _ = wrongs:=!wrongs +1 in raise wrong_pass ) ; retrieve=(fun (p: passwd) (amt:in... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right ( fun (e2:('a*'a*weight)) acc -> match e2 with | (v1,v2,w) when (v1=vertex) -> (v2,w)::acc | _ -> 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 (a,w)=node in let ns=(neighbours (g) (fst(node))) in if (not(List.mem (fst(node)) visited) ) then if (List.exists (fun x->fst(x) = b) (ns)) then let lE=(List.find (fun x... |
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 (a,w)=node in let ns=(neighbours (g) (fst(node))) in if (not(List.mem (fst(node)) visited) ) then if (List.exists (fun x->fst(x) = b) (ns)) then let lE=(List.find ... |
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 account = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !account then (attempts := 0; account := new_pass) else (attempts := !attempts + 1; raise wrong_pass)); retrieve = (fun pass w... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let out_neigh acc e = match e with | (v, out, w) when v = vertex -> (out, w) :: acc | _ -> acc in List.fold_left out_neigh [] 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 List.mem n visited then raise Fail else if n = b then ([n], w) else let next = aux_list (neighbours g n) (n :: visited) in (n :: fst next, w + snd next... |
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 List.mem n visited then fc () else if n = b then sc ([n], w) else let succ = (fun nd -> sc (n :: fst nd, w + snd nd)) in aux_list (neighbours g n... |
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 weights = fun x y -> snd x - snd y in List.nth_opt (List.rev (List.sort weights paths)) 0 ;; |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let pwd = ref initial_pass in let failures = ref 0 in { update_pass = (fun pwd1 pwd2 -> if pwd1 = !pwd then (failures := 0; pwd := pwd2 ) else (failures := !failures + 1; raise wrong_pass)); retrieve = (fun pwd1 money -> if !failures >= 5 t... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x (a,b,c) -> if a = vertex then x@[(b,c)] else x) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (w: weight) (visited : 'a list) : ('a list * weight) = if List.exists (fun a -> a = node) visited then raise Fail else node :: visited; aux_list (neighbours g a) visited and aux_list (nodes: ('a * weight) list) (visited: 'a l... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a )(w: 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 x = ref initial_pass in let balance = ref 0 in let count = ref 0 in let negative b = (if b < 0 then raise negative_amount) in let enough b = (if b > !balance then raise not_enough_balance) in let check a = (if a <> !x || !count >= 5 then (count:= !count + 1; ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let l = ref [] in let d a = (a :: !l) in let c a = l := d a in let x b = (if (get_x b) = vertex then c ((get_y b),(get_z b))) in let _ = List.iter x g.edges in !l ;; let get_first xy = let (x,y) = xy in x;; let get_last xy = let (x,y) = xy in y;; |
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) = if (get_first node) = b then ((get_first node) :: (get_first visited), (get_last visited) + (get_last node)) else (if List.length (neighbours g (get_first node)) =... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited: ('a list * weight)) fc sc : ('a list * weight)= if (get_first node) = b then sc ((get_first node) :: (get_first visited), (get_last visited) + (get_last node)) else ( if List.length (neighbours g (get_firs... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all = find_all_paths g a b in if all = [] then None else Some (List.fold_left (fun x y -> if (get_last y) >= (get_last x) then y else x) ([], 0) all );; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let nb_fail = ref 0 in let balance = ref 0 in { update_pass = (fun old_pass new_pass -> if (old_pass = !pass) then (nb_fail := 0; pass := new_pass) else (nb_fail := !nb_fail + 1; raise wrong_pass) ); retrieve = (fun old_pass amount ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun lst edge -> let (v, neigh, weight) = edge in if v = vertex then (neigh, weight) :: lst else lst) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (visited : 'a list) : ('a * weight) list = if List.length (List.filter ((=) node) visited) > 0 || node = b then [] else let newe = List.filter (fun n -> let (neigh, _, _) = n in neigh = node) g.edges in List.map (fun n -> let... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (visited : 'a list) : ('a * weight) list = if List.length (List.filter ((=) node) visited) > 0 || node = b then [] else let newe = List.filter (fun n -> let (neigh, _, _) = n in neigh = node) g.edges in List.map (fun n -> le... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest_path (lst: ('a list * weight) list) (longest: ('a list * weight)) (cost: int) : ('a list * weight) = match lst with | [] -> longest | x::xs -> let (p, c) = x in if c > cost then longest_path xs x c else longest_path xs lon... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let password = ref initial_pass in let failure_count = ref 0 in let check_failures = (fun () -> if !failure_count >= 5 then raise too_many_failures) in let check_password = (fun (pass: passwd) -> if pass <> !password then (failure_count := ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let matched_vertex = fun (v1, v2, w) acc -> if vertex = v1 then (v2, w) :: acc else acc in List.fold_right matched_vertex g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node_a, node_w): 'a * weight) (visited : 'a list) : ('a list * weight) = if List.mem node_a visited then raise Fail else if node_a = b then (visited @ [node_a], node_w) else;; |
let neighbours = List.map (fun (x, y) -> (x, y + node_w) ) (neighbours g node_a) in try aux_list neighbours (visited @ [node_a]) with Fail -> raise Fail and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = match nodes with | [] -> raise Fail | x :: xs -> try aux_node x visited with Fail ->... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node_a, node_w): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if List.mem node_a visited then fc () else if node_a = b then sc (visited @ [node_a], node_w) else;; |
let neighbours = List.map (fun (x, y) -> (x, y + node_w) ) (neighbours g node_a) in aux_list neighbours (visited @ [node_a]) fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = match nodes with | [] -> fc () | x :: xs -> let fc2 = fun () -> aux_list xs visited fc sc in aux_nod... |
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let rec aux_node ((node_a, node_w): 'a * weight) (visited : 'a list) : ('a list * weight) list = if List.mem node_a visited then [] else if node_a = b then [([node_a], node_w)] else;; |
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 | x :: xs -> let rec find_max remaining_paths longest_path = match remaining_paths with | [] -> longest_path | p :: ps -> let new_longest = if snd p > snd longest_path then... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes = _; edges = edgesList } = g in List.fold_left (fun listAcc (startV, endV, weight) -> if startV = vertex then (listAcc @ [(endV, weight)]) else listAcc) [] edgesList ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node) = b then ([fst node], snd node) else if List.mem (fst node) visited then raise Fail else let (nodePath, totalCost) = aux_list (neighbours g (fst node)) ((fst 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 sc : ('a list * weight)= if (fst node) = b then sc ([fst node], snd node) else if List.mem (fst node) visited then fc () else let sc' = (fun (path, cost) -> sc ((fst node) :: path, (snd node) ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec findLongest allPaths longestPath longestLen : ('a list * weight) option = match allPaths with | [] -> Some longestPath | (path, w) :: t -> if w > longestLen then findLongest t (path, w) w else findLongest t longestPath longestLen ... |
let new_status_manager (max_number_failures : int) : bank_account_status_manager = let counter = ref 0 and status = ref Unlocked in { show = (fun () -> !status); reset = ( fun () -> begin counter := 0; status := Unlocked end ); tick = ( fun () -> if !status = Unlocked then begin counter := !counter + 1; if !counter = m... |
let open_account (initial_pass : passwd) : bank_account = let balance = ref 0 in let pass = ref initial_pass in let status_manager = new_status_manager(5) in { update_pass = ( fun current_pass new_pass -> if !pass = current_pass then begin status_manager.reset(); pass := new_pass end else begin status_manager.tick(); r... |
let neighbours (g : 'a graph) (vertex : 'a) : ('a * weight) list = List.map (fun (_, v, w) -> (v, w)) (List.filter (fun (u, _, _) -> (u = vertex)) g.edges);; |
let find_path (g : 'a graph) (a : 'a) (b : 'a) : ('a list * weight) = let rec aux_node ((c, v) : 'a * weight) (visited : 'a list) : ('a list * weight) = if c = b then ([b], v) else if not (List.mem c visited) then let (p, w) = aux_list (neighbours g c) (c::visited) in (c::p, w+v) else raise Fail and aux_list (nodes : (... |
let find_path' (g : 'a graph) (a : 'a) (b : 'a) : ('a list * weight) = let rec aux_node ((c, v) : 'a * weight) (visited : 'a list) (fc : unit -> ('a list * weight)) (sc : ('a list * weight) -> ('a list * weight)) : ('a list * weight) = if c = b then sc ([b], v) else if not (List.mem c visited) then aux_list (neighbours... |
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 | _ -> Some ( List.fold_left ( fun (p, w) (q, v) -> if w > v then (p, w) else (q, v) ) ([], -1) paths );; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let numAttempts = ref 0 in let balance = ref 0 in let password_checker pass bank_account_func = if pass = !password then (numAttempts := 0; bank_account_func ()) else (numAttempts := !numAttempts + 1; raise wrong_pass) in let at... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = [];; |
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 ();; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.