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) fc sc : ('a list * weight)= let (w,v)=node in if w=b then let (c,d)=sc() in (c@[w],d+v) else if List.mem w visited then fc() else aux_list(neighbours g w)(visited@[w])(fc)(fun()-> let (x,y)=sc() ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths=find_all_paths(g)(a)(b) in if paths=[] then None else let (t,u)=List.nth paths 0 in let rec pred(paths:('a list * weight) list)(biggest:int)(list_with_biggest:('a list *weight))= match paths with |[]-> list_with_biggest |(a,b)::... |
let open_account (initial_pass: passwd) : bank_account = let pass= ref initial_pass in let balance= ref 0 in let wrongcount= ref 0 in let resetcount()= wrongcount:=0 in let resetpass(inputpass:passwd)= pass:= inputpass ; wrongcount:= 0 in let negativeinput(amount:int)=if amount<0 then raise negative_amount in let wrong... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let pred((a,b,c):'a*'a*weight)= a=vertex in let y=List.filter pred g.edges in let f((a,b,c):'a*'a*weight)=(b,c) in List.map f y;; |
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 (i,j)=node in if List.mem i visited then raise Fail else if i=b then ([i],j) else (let visited=visited@[i] in let (path,total)=aux_list (neighbours g i) (visited) in ([i... |
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 (w,v)=node in if w=b then let (c,d)=sc() in (c@[w],d+v) else if List.mem w visited then fc() else aux_list(neighbours g w)(visited@[w])(fc)(fun()-> let (x,y)=sc() ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths=find_all_paths(g)(a)(b) in if paths=[] then None else let (t,u)=List.nth paths 0 in let rec pred(paths:('a list * weight) list)(biggest:int)(list_with_biggest:('a list *weight))= match paths with |[]-> list_with_biggest |(a,b)::... |
let open_account (initial_pass: passwd) : bank_account = let pass= ref initial_pass in let balance= ref 0 in let wrongcount= ref 0 in let resetcount()= wrongcount:=0 in let resetpass(inputpass:passwd)= pass:= inputpass ; wrongcount:= 0 in let negativeinput(amount:int)=if amount<0 then raise negative_amount in let wrong... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let pred((a,b,c):'a*'a*weight)= a=vertex in let y=List.filter pred g.edges in let f((a,b,c):'a*'a*weight)=(b,c) in List.map f y;; |
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 (i,j)=node in if List.mem i visited then raise Fail else if i=b then ([i],j) else (let visited=visited@[i] in let (path,total)=aux_list (neighbours g i) (visited) in ([i... |
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 (w,v)=node in if w=b then let (c,d)=sc() in (c@[w],d+v) else if List.mem w visited then fc() else aux_list(neighbours g w)(visited@[w])(fc)(fun()-> let (x,y)=sc() ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths=find_all_paths(g)(a)(b) in if paths=[] then None else let (t,u)=List.nth paths 0 in let rec pred(paths:('a list * weight) list)(biggest:int)(list_with_biggest:('a list *weight))= match paths with |[]-> list_with_biggest |(a,b)::... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let counter = ref 0 in { update_pass = (fun (initial_pass:passwd) (new_pass:passwd) -> if initial_pass = !pass then (counter := 0; pass := new_pass) else (counter := !counter + 1; raise wrong_pass)); show_bala... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let e = g.edges in let rec n e vertex acc = match e with |[] -> acc |(vert1,vert2,weight) :: e' -> if vert1 = vertex then n e' vertex ((vert2,weight)::acc) else n e' vertex acc in n e vertex [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (x: ('a * weight)) (visited: ('a list * weight))= if fst x = b then ( (fst visited)@[(fst x)] , snd x + (snd visited)) else if List.mem (fst x) (fst visited) then raise Fail else aux_list (neighbours g (fst x)) ((fst visited)@[(fst x)],... |
let find_path' g a b= aux_list (neighbours g a) visited (fun () -> raise Fail) (fun r -> r);; *);; |
let find_path' g a b :('a list * weight) = let rec aux_node (node, w) visited (fc: (unit ->'a list * weight)) 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 aux_list... |
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 longest = ref ([a],0) in let rec find_longest p = match p with |[] -> Some !longest |x::xs -> if (snd x) >= snd !longest then (longest := x; find_longest xs) else find_longest xs in find_lon... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let password = ref initial_pass in let failed_attempts = ref 0 in let check_pw (pw: passwd) = if !failed_attempts >= 5 then raise too_many_failures else if pw <> !password then ( failed_attempts := (!failed_attempts + 1); raise wrong_pass )... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let out_edges: ('a * 'a * weight) list = List.filter (fun ((v, u, w): ('a * 'a * weight)) -> v = vertex) g.edges in List.map (fun ((v, u, w): ('a * 'a * weight)) -> (u, w)) out_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) = if (fst node) = b then ([(fst node)], (snd node)) else let unvisited_adjacent_nodes: ('a * weight) list = List.filter (fun (v, w) -> not (List.mem v visited)) (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)= if (fst node) = b then sc (node) else let unvisited_adjacent_nodes: ('a * weight) list = List.filter (fun (v, w) -> not (List.mem v visited)) (neighbours g (fst node))... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let longest (p1: ('a list * weight)) (p2: ('a list * weight)) = if ((snd p1) >= (snd p2)) then p1 else p2 in let paths: ('a list * weight) list = find_all_paths g a b in match paths with | [] -> None | x::xs -> Some (List.fold_left longes... |
let open_account (initial_pass: passwd) : bank_account = let wrong_pwd_counter = ref 0 in let passwd_cur = ref initial_pass in let balance = ref 0 in let check_password pwd = pwd = (!passwd_cur) in let check_amount money = if money < 0 then raise negative_amount in let check_balance money = if money > !balance then rai... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc edge -> match edge with | (target, neighbour, w) when target = vertex -> (neighbour, 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 (key, w) = node in if key = b then ([key], w) else if List.mem key visited then raise Fail else let (path, w') = aux_list (neighbours g key) (key :: visited) in (key :: ... |
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 (key, w) = node in if key = b then sc ([key], w) else if List.mem key visited then fc () else aux_list (neighbours g key) (key :: visited) fc (fun (path, w') -> 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 :: tl -> let rec helper cur res = let (_, w) = cur in match res with | [] -> Some cur | h :: t -> let (_, w') = h in let cur' = if w' > w then h else cur in helper cur' t in helper hd tl ;... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass and bal = ref 0 and attempts = ref 0 in {update_pass = (fun (old: passwd) (new_ : passwd) -> if !pass = old then (attempts := 0; pass := new_) else (attempts := (!attempts + 1);raise wrong_pass)) ; retrieve = (fun (input_pass: passwd) ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f (acc: ('a * weight) list) (edges: ('a * 'a * weight) ) : ('a * weight) list = let (v1, v2, w) = edges in (if v1 = vertex then (v2, w) :: acc else acc) in List.fold_left f [] g.edges ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let sum = ref 0 in 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 () and nextNode (neighbour: ('a * weig... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let sum = ref 0 in 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 () and nextNode (neighbour... |
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 List.length all_paths = 0 then None else let rec check (l : ('a list * weight) list) (path: 'a list) (cur_weight : weight) : ('a list * weight) option = match l with | [] -> Some (path , cur_weig... |
let makeCounter () : counter = let localcount = ref 0 in { increase = (fun () -> localcount := !localcount + 1; !localcount) ; reset = (fun () -> localcount := 0) ; show = (fun () -> !localcount) } ;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let c = makeCounter () in { update_pass = (fun pass newpass -> if pass <> !password then (c.increase (); raise wrong_pass) else (c.reset (); password := newpass) ) ; retrieve = (fun pass debit -> if pass <... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f ((a, b, c): ('a * 'a * weight)) (l: ('a * weight) list) = if a = vertex then [b, 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 path_list = ref [a] in let weight_acc = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let temp_path = !path_list in let temp_weight = !weight_acc in let curNode = fst node in let curWeight = snd node in if ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let path_list = ref [a] in let weight_acc = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let temp_path = !path_list in let temp_weight = !weight_acc in let curNode = fst node in let curWeight = snd node ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let outputlist = ref [] in let outputweight = ref 0 in let (l: ('a list * weight) list) = find_all_paths g a b in let rec helper l1 : unit = match l1 with | [] -> () | hd :: tl -> if (snd hd) > !outputweight then begin outputlist := (fst ... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let num_failure = ref 0 in let password = ref initial_pass in { update_pass = (fun old_passwd new_passwd -> if old_passwd = (!password) then (num_failure := 0; password := new_passwd) else (num_failure := (!num_failure) + 1; raise wrong_pas... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun output_list (v, neighbour, cost) -> if v = vertex then (neighbour, cost)::output_list else output_list ) [] 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) acc: ('a list * weight) = let (v2, w) = node in if v2 = b then ( List.append visited [v2], w+acc) else if List.mem v2 visited then raise Fail else aux_list (neighbours g v2) (List.append visited [... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v2, w2) = node in if v2 = b then sc ([v2], w2) else if List.mem v2 visited then fc () else aux_list (neighbours g v2) (v2::visited) fc (fun (v, w) -> sc (v2::v,w2... |
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 let rec to_find paths = match paths with | [] -> None | (p1, w1) :: tl -> match tl with | [] -> Some (p1, w1) | (p2, w2) :: tl2 -> if List.length p1 >= List.length p2 then to_find ((p1, w1) ::tl2) e... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let num_failure = ref 0 in let password = ref initial_pass in { update_pass = (fun old_passwd new_passwd -> if old_passwd = (!password) then (num_failure := 0; password := new_passwd) else (num_failure := (!num_failure) + 1; raise wrong_pas... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun output_list (v, neighbour, cost) -> if v = vertex then (neighbour, cost)::output_list else output_list ) [] 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) acc: ('a list * weight) = let (v2, w) = node in if v2 = b then ( List.append visited [v2], w+acc) else if List.mem v2 visited then raise Fail else aux_list (neighbours g v2) (List.append visited [... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v2, w2) = node in if v2 = b then sc ([v2], w2) else if List.mem v2 visited then fc () else aux_list (neighbours g v2) (v2::visited) fc (fun (v, w) -> sc (v2::v,w2... |
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 let rec to_find paths = match paths with | [] -> None | (p1, w1) :: tl -> match tl with | [] -> Some (p1, w1) | (p2, w2) :: tl2 -> if List.length p1 > List.length p2 then to_find ((p1, w1) ::tl2) el... |
let open_account (initial_pass: passwd) : bank_account = let currpass = ref initial_pass and currbal = ref 0 and tries = ref 0 in let checkpass = if !tries >= 5 then raise too_many_failures in {update_pass = (fun oldpass newpass -> if !currpass <> oldpass then begin tries := !tries + 1; raise wrong_pass end else begin ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (_,v2,w) -> (v2,w)) (List.filter (fun (v1,_,_) -> vertex = v1) g.edges) let typ1 = {nodes = ["LocA"; "LocB"; "LocC"]; edges = [("LocC", "LocB", 5);("LocA","LocC", 3)]};; |
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 with |(v,w) when (v = b) -> [v], w |(v,w) -> if List.mem v visited then raise Fail else let (ls, w2) = aux_list (neighbours g v) (v::visited) in (v::ls, w+w2) 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)= match node with |(v,w) when (v = b) -> sc [v], w |(v,w) -> if List.mem v visited then raise Fail else let suc2 = sc in let fail2 = fun () -> aux_list (neighbours g v) ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let m = find_all_paths g a b in let rec max_in_list l = match l with |[] -> None |x::[] -> Some x |(c,r)::xs -> let Some (v,w) = max_in_list xs in if r > w then Some (c,r) else Some (v,w) in max_in_list m;; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let wrong = ref 0 in let update_pass ps1 ps2 = if not (ps1 = !pass) then ( wrong := !wrong + 1; raise wrong_pass ) else ( pass := ps2; wrong := 0 ) in let deposit pswd amount = if !wrong >= 5 then raise too_ma... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper node acc edge = let (a, b, c) = edge in if a = node then (b, c) :: acc else acc in List.fold_left (helper vertex) [] g.edges ;; 8255;; |
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 pass = ref initial_pass in let pass_attempts = ref 0 in let balance = ref 0 in { update_pass = (fun p1 p2 -> if (p1 = !pass) then (pass_attempts := 0; pass := p2) else (pass_attempts := (!pass_attempts + 1); raise wrong_pass) ); retrieve = (fun p amount -> if... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let out_edges = List.filter (fun (x, _, _) -> x = vertex) g.edges in List.map (fun (_, o, w) -> (o, w)) out_edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let total_weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let _ = (total_weight := !total_weight + (snd node)) in let out_nodes = neighbours g (fst node) in let filtered = List.filter (fun n -> not (List... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let total_weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let _ = (total_weight := !total_weight + (snd node)) in let out_nodes = neighbours g (fst node) in let filtered = List.filter (fun n -> not... |
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 (List.length all_paths > 0) then let rec max_path max_edge others = match others with | [] -> Some max_edge | (edges, w)::other_edges -> let (_, weight) = max_edge in if (w > weight) then max_pat... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let pass_attempts = ref 0 in let balance = ref 0 in { update_pass = (fun p1 p2 -> if (p1 = !pass) then (pass_attempts := 0; pass := p2) else (pass_attempts := (!pass_attempts + 1); raise wrong_pass) ); retrieve = (fun p amount -> if... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let out_edges = List.filter (fun (x, _, _) -> x = vertex) g.edges in List.map (fun (_, o, w) -> (o, w)) out_edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let total_weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let _ = (total_weight := !total_weight + (snd node)) in let out_nodes = neighbours g (fst node) in let filtered = List.filter (fun n -> not (List... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let total_weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let _ = (total_weight := !total_weight + (snd node)) in let out_nodes = neighbours g (fst node) in let filtered = List.filter (fun n -> not... |
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 (List.length all_paths > 0) then let rec max_path max_edge others = match others with | [] -> Some max_edge | (edges, w)::other_edges -> let (_, weight) = max_edge in if (w > weight) then max_pat... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let counter = ref 0 in let lock_account = if (!counter >= 5) then raise too_many_failures in let update_pass (old_pass: passwd) (new_pass: passwd) = match old_pass with | initial_pass -> let initial_pass = new_pass in () | _ -> raise wrong_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = notimplemented ();; |
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 balance = ref 0 in let curr_pass = ref initial_pass in let tries = ref 0 in { update_pass = (fun pass p -> if pass = !curr_pass then (tries := 0;curr_pass := p) else (tries:= !tries + 1;raise wrong_pass) ); retrieve = (fun pass d -> if !tries > 4 then raise t... |
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: 'a * weight) (visited : 'a list) : ('a list * weight) = match node with | (v,w) when v = b -> (visited@[v], w) | (v,_) when List.mem v visited -> raise Fail | (v,w) -> aux_list (List.map (fun (x,c) -> (x,c+w)) (neighbours g v)) (... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc = match node with | (v,w) when v = b -> sc (visited@[v], w) | (v,_) when List.mem v visited -> fc () | (v,w) -> aux_list (List.map (fun (x,c) -> (x,c+w)) (neighbours g v)) (visited@[v]) fc ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = List.fold_left( fun acc (p,c) -> match acc with | None -> Some (p,c) | Some ((pl,cl)) when c > cl -> Some (p,c) | Some (pl,cl) -> Some (pl,cl) ) None (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let attempt = ref 0 in let balance = ref 0 in let password = ref initial_pass in { update_pass = (fun pi pf -> if (pi <> !password) then (attempt := !attempt +1; raise wrong_pass) else password := pf; attempt := 0; ); retrieve = (fun p amount -> if (!attempt >= 5... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let e = g.edges in let af_filter = List.filter (fun x-> let (a,_,_) = x in a = vertex )e in List.map (fun x -> let (_,b,w) = x in (b, w)) af_filter;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = match neighbours g (fst(node)) with |[] -> (if (fst(node) <> b) then raise Fail else (visited, !weight)) |x::xs -> if (fst(x) = b) then (visited @ [fst... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= match neighbours g (fst(node)) with |[] -> (if (fst(node) <> b) then fc raise Fail else (sc [], !weight)) |x::xs -> if (fst(x) = b) then (sc [] @... |
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 a b = if (a>b) then a else b in let rec list_max p = match p with | [] -> None | x :: xs -> match list_max xs with | None -> Some x | Some xxs -> Some (max x xxs) in list_max paths;; |
let open_account (initial_pass: passwd) : bank_account = let account = ref (initial_pass, 0, 0) in { update_pass = (fun old_pass new_pass -> let (pass, balance, failures_count) = !account in if old_pass = pass then account := (new_pass, balance, 0) else (account := (pass, balance, (failures_count + 1)); raise wrong_pas... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun edge acc -> let (curr_node, dest_node, curr_weight) = edge in if curr_node = vertex then List.append acc [(dest_node, curr_weight)] 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) w_total : ('a list * weight) = if List.mem (fst(node)) visited then raise Fail else if fst(node) = b then ((visited @ [fst(node)]), (w_total + snd(node))) else aux_list (neighbours g (fst(node))) ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) w_total fc sc : ('a list * weight)= if fst(node) = b then sc(((visited @ [fst(node)]), (w_total + snd(node)))) else if List.mem (fst(node)) visited then fc () else aux_list (neighbours g (fst(nod... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec calc_longest_path (all_paths: ('a list * weight) list) (max: ('a list * weight)) = match all_paths with |[] -> if max = ([], 0) then None else Some max |x::xs -> if snd(x) > snd(max) then calc_longest_path xs x else calc_longest_p... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let password = ref initial_pass in let counter = ref 0 in { update_pass = (fun old_pass -> fun new_pass -> if old_pass = !password then let _ = (counter := 0) in password := new_pass else let _ = (counter := !counter +1) in raise wrong_pass... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let v1 (a,b,c) = a in let v2 (a,b,c) = b in let v3 (a,b,c) = c in List.fold_left (fun x y -> if not (List.exists (fun z -> z = vertex) g.nodes) then [] else if vertex = (v1 y) then (v2 y, v3 y)::x else x ) [] 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 rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node) = b then (!path, !w) else let n = neighbours g (fst node) in aux_list n ((fst node)::visited) 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)= if (fst node) = b then sc ([], 0) else let n = neighbours g (fst node) in aux_list n ((fst node)::visited) fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_max list = match list with | [] -> 0 | hd::tl -> max (snd hd) (find_max tl) in let rec find_list list w = match list with | [] -> None | hd::tl -> if (snd hd) = w then Some hd else find_list tl w in let l = find_all_paths g a... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let password = ref initial_pass in let failures = ref 0 in let verifypass pass = (if pass = !password then (failures:=0; true) else (failures:=!failures+1; false)) in let exceededattempts() = (!failures)>=5 in { update_pass = (fun oldpass n... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec findneighbour edges = match edges with | [] -> [] | (s,t,w) :: xs -> if s = vertex then (t,w)::(findneighbour xs) else findneighbour xs in findneighbour 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) = if ((fst node)=b) then ([b],0) else aux_list (neighbours g (fst node)) ((fst node)::visited) and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * 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 (current,w)= node in if (current = b) then sc current ([b],w) else aux_list (neighbours g current) current (current::visited) fc ( fun curr (path,weight)->if path =... |
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 rec longest = fun l -> match l with | [] -> ([],0) | (path,weight)::xs -> let (longestpath, longestcost) = longest xs in if (weight >longestcost) then (path,weight) else (longestpath,longestcost) in... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let wrong_pass_count = ref 0 in let locked = ref false in { update_pass = (fun oldpass newpass -> if oldpass = !password then (locked := false; wrong_pass_count := 0; password := newpass) else (wrong_pass_... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.