text stringlengths 0 601k |
|---|
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = fun (v1, v2, i) l -> if v1 = vertex then (v2, i) :: 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 f w (a, weight) = (a, weight + w) in let (n, w) = node in if List.mem n visited then raise Fail else match (n, w) with | (x1, _) when b = n -> (List.rev (n :: 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 f w (a, weight) = (a, weight + w) in let (n, w) = node in if List.mem n visited then fc () else match (n, w) with | (x1, _) when b = n -> (List.rev (n :: visited),... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l = find_all_paths g a b in let (l_max, m) = get_max_path l in if m = (-1) then None else Some (l_max, m);; |
let open_account (initial_pass: passwd) : bank_account = let account_password = ref initial_pass in let num_auth_failures = ref 0 in let balance = ref 0 in let update_pass (acct_p : passwd) (new_p : passwd) = if (acct_p = !account_password) then begin account_password := new_p ; if (!num_auth_failures >= 5) then num_au... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge_list = g.edges in let neighbors_list = [] in let rec compile_neighbor_list edges acc = match edges with | [] -> acc | edge::t -> let (v,out,w) = edge in if (v = vertex) then compile_neighbor_list t ((out, w)::acc) else compile_neighbor_list t acc... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec in_visited (node: 'a) (visited: 'a list) : bool = List.exists (fun x -> (x = node)) visited in let rec remove_n (n: 'a) (w: int) (acc : ('a list * weight)) (new_list : ('a list)) = let (l,tw) = acc in match l with | [] -> (new_list, tw) | x::t -... |
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 account_password = ref initial_pass in let num_auth_failures = ref 0 in let balance = ref 0 in let update_pass (acct_p : passwd) (new_p : passwd) = if (acct_p = !account_password) then begin account_password := new_p ; if (!num_auth_failures >= 5) then num_au... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge_list = g.edges in let neighbors_list = [] in let rec compile_neighbor_list edges acc = match edges with | [] -> acc | edge::t -> let (v,out,w) = edge in if (v = vertex) then compile_neighbor_list t ((out, w)::acc) else compile_neighbor_list t acc... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec in_visited (node: 'a) (visited: 'a list) : bool = List.exists (fun x -> (x = node)) visited in let rec remove_n (n: 'a) (w: int) (acc : ('a list * weight)) (new_list : ('a list)) = let (l,tw) = acc in match l with | [] -> (new_list, tw) | x::t -... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec in_visited (node: 'a) (visited: 'a list) : bool = List.exists (fun x -> (x = node)) visited in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= notimplemented() and aux_list (nodes: ('a * weight) list) (visit... |
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 find_longest (list : ('a list * weight) list) (cur_longest: int) (cur_longest_index : int) (cur_index : int) = match list with | [] -> cur_longest_index | (nodes, w)::t -> if ((List.length n... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let attemps = ref 0 in let balance = ref 0 in let security p f = if !attemps >= 5 then raise too_many_failures else (if p = !pass then (attemps := 0; f ()) else (attemps := !attemps+1 ; raise wrong_pass)) in let update_pass prev cur... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let elist = g.edges in let f (init: ('a *weight) list) (edge: ('a * 'a * weight)) : ('a *weight) list = let (v1, v2, w) = edge in match v1 with | v when v=vertex -> (v2, w) :: init | _ -> init in List.fold_left f [] elist;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nb = neighbours g a in let rec aux_node (node: 'a * weight) (visited : 'a list) (weight: int): ('a list * weight) = let (v, w) = node in if (List.mem v visited) then raise Fail else if v=b then (visited @ [v], weight + w) else aux_list (neighbours g... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v, w) = node in if List.mem v visited then fc () else if v=b then sc (visited@[v]) w else aux_list (neighbours g v) (visited @ [v]) fc (fun l' w' -> sc l' (w+w'))... |
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 f p1 p2 = let (l1, w1) = p1 and (l2, w2) = p2 in if w1 < w2 then p2 else p1 in match all_paths with | [] -> None | path :: pl -> Some (List.fold_left f path pl);; |
let open_account (initial_pass: passwd) : bank_account = let incorrect_count = ref 0 in let cur_pass = ref initial_pass in let balance = ref 0 in let pass_validator (pass: passwd): bool = if !incorrect_count >= 5 then raise too_many_failures else if pass = !cur_pass then let _ = incorrect_count := 0 in true else let _ ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let filter (u, _, _) = (u = vertex) in let filtered = List.filter filter g.edges in List.map (fun (_, v, w) -> (v, w)) filtered;; |
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 if a = b then ([b], w) else let path, w2 = aux_list (neighbours g a) (a :: visited) in (a :: path, w + w2) and aux_list (nodes: ('a * weight) list) (visit... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec do_all f lst = match lst with | [] -> ([], 0) | x :: xs -> let res = f x in if res = ([], 0) then do_all f xs else res in let rec dfs (node: 'a * weight) (visited: 'a list) sc : ('a list * weight) = let u, _ = node in if u = b then sc ([], 0) e... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max u acc = let p1, w1 = acc in let p2, w2 = u in if w2 > w1 then (p2, w2) else (p1, w1) in let paths = find_all_paths g a b in match paths with | [] -> None | _ -> Some (List.fold_left (max) ([], 0) paths );; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let attempts = ref 5 in let balance = ref 0 in let update_pass (old_passwd: passwd) (new_passwd: passwd) : unit = if old_passwd = !password then let temp = password := new_passwd in attempts := 5 else let temp = attempts := !att... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neighbour_helper (edges: ('a * 'a * weight) list) (vertex: 'a) (acc: ('a * weight) list) : ('a * weight) list = match edges with | [] -> acc | edge::rest -> let (a, b, c) = edge in if a = vertex then neighbour_helper rest vertex ((b, c)::acc) else... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let pathWeight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (_val, _weight) = node in let temp = pathWeight := !pathWeight + _weight in if _val = b then (_val::visited, !pathWeight) else let pruned_visit... |
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 (_val, _weight) = node in if _val = b then sc () else let pruned_visitors = prune_visited (neighbours g _val) visited in aux_list pruned_visitors (visited) fc sc a... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec return_longest_path (paths : ('a list * weight) list) (longest: ('a list * weight) option) : ('a list * weight) option = match paths with | [] -> longest | path::rest -> match longest with | None -> return_longest_path rest (Some ... |
let open_account (initial_pass: passwd) : bank_account = let passwd = ref initial_pass in let balance = ref 0 in let count = ref 0 in { update_pass = (fun a b -> if a = !passwd then (count := 0; passwd := b) else (count := !count + 1; raise wrong_pass)) ; retrieve = (fun a b -> if !count <= 4 then if a = !passwd then i... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get_next x y = let v1, v2, w = x in if v1 = vertex then (v2, w)::y else y in List.fold_right (get_next) g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (sum: int) : ('a list * weight) = let name, weight = node in if name = b then (visited, sum) else aux_list (neighbours g name) visited sum and aux_list (nodes: ('a * weight) list) (visited: 'a lis... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (sum: int) fc sc : ('a list * weight)= let name, weight = node in if name = b then sc (visited, sum) else aux_list (neighbours g name) visited sum fc sc and aux_list (nodes: ('a * weight) list) (... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let if_longer x y = let new_sites, new_val = x in match y with | Some n -> let old_sites, old_val = n in if new_val > old_val then Some x else y | None -> Some x in List.fold_right (if_longer) (find_all_paths g a b) None;; |
let count = ref 0;; let makecounter () = { increase = (fun () -> incr count; !count) ; reset = (fun () -> count := 0) } let check_attempts (c: counter) = let attempt = c.increase () in if attempt < 5 then raise wrong_pass else count := attempt ; raise too_many_failures;; |
let open_account (initial_pass: passwd) : bank_account = let current_pass = ref initial_pass in let balance = ref 0 in let c = makecounter () in let update_pass : passwd -> passwd -> unit = fun old_pass new_pass -> if old_pass = !current_pass then current_pass := new_pass else check_attempts c in let deposit : passwd -... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let l = ref [] in match g with | {nodes; edges} -> List.fold_left (fun x y -> match y with | (v1, v2, w) when v1 = vertex -> let pair = (v2, w) in l := [pair] @ !l ; !l | _ -> if List.mem vertex nodes then l:= [] @ !l else l:= []; !l ) (l:= []; !l) edges;... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let path_nodes = ref [a] in let path_weight = ref 0 in let n = neighbours g a in let visited = [a] in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = match node with | (x, w) when List.mem x visited -> raise Fail | (x, w)... |
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 pwd = ref initial_pass in let balance = ref 0 in let tries = ref 0 in let comparator a b = if (b<0) then raise negative_amount else (if b> !a then raise not_enough_balance else a := !a-b) in { update_pass = (fun x (y:passwd)-> if (!pwd = x) then (tries := 0 ;... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let aux_fil x (a,_,_) = if a=x then true else false in let l1 = List.filter (aux_fil vertex) g.edges in let f1 (_,b,c) = (b,c) in List.map f1 l1;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let aux5 (a,b1) = a in let aux6 (a,b) = b in let aux2 a (b,c) = if a=b then true else false in let aux1 a b = if a = b then true else false in let rec aux4 l1 acc1 acc2 = match l1 with | [] -> (acc1,acc2) | h::t -> aux4 t ( ((aux5 h)::acc1)) ((aux6 h)+a... |
let find_path' (g: 'a graph) (a: 'a) (target: 'a) = let aux1 (x1,_) = x1 in let aux2 (_,y2) = y2 in let aux3 (a,a1) b = if a = b then true else false in let rec aux4 acc1 acc2 l1 = match l1 with | [] -> (acc1,acc2) | h::t -> aux4 ((aux1 h)::acc1) ((aux2 h)+acc2) t in let aux5 z4 z5 (z1,z2,z3)= (z1=z4 && z2=z5) in let a... |
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let f1 (a,b) = a in let pred1 string1 string2 (s1,s2,_) = (string1=s1 && string2=s2) in let fun1 (_,_,i1) = i1 in let rec make_up_aux graph target acc list1 = match list1 with |[]-> acc |h::t -> if (h=target) then acc else make_up_aux graph ta... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let fun1 (_,i1) = i1 in let paths = find_all_paths g a b in let rec aux l1 acc = match l1 with | [] -> if acc= ([],0) then None else Some acc | h::t -> if (fun1 h)>(fun1 acc) then aux t h else aux t acc in aux paths ([],0);; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let update_pass (old_pass: passwd) (new_pass: passwd) : unit = let p = !pass in if(String.equal old_pass p) then let c = counter := 0 in pass := new_pass else let c = counter := !counter... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let has_edge ((v1, v2, w): 'a * 'a * weight) : bool = String.equal v1 vertex in let get_v_w (edge: 'a * 'a * weight) : ('a * weight) = let (v1, v2, w) = edge in (v2, w) in let edge_list = List.filter has_edge g.edges in List.map get_v_w edge_list ;; let r... |
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 (v, w) = node in if(String.equal v b) then ([v], w) else try let (rest, mg) = aux_list (neighbours g v) visited in (v :: rest, w + mg) with Fail -> 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)= 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 = try let all_paths = find_all_paths g a b in get_longest_path all_paths all_paths 0 with Fail -> None ;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let failedPwd = ref 0 in let authorizeC (pwd: passwd) (operation: 'a -> unit) input = if (!failedPwd = 5) then raise too_many_failures else let _ = failedPwd := 0 in match !password with | p when p = pwd -... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let { edges } = g in let outboundEdges = List.filter (fun edge -> let (n1, _, _) = edge in n1 = vertex) edges in List.fold_right (fun edge list -> (let (_, n2, w) = edge in [(n2, w)]@list)) outboundEdges [] ;; |
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 (nod, weight) = node in match nod with | n when n = b -> ([nod], weight) | _ -> ( let nbs = neighbours g nod in let (path, w) = aux_list nbs ([nod] @ visited) in match p... |
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 check_attempts (attempt : int) = if attempt >= 5 then raise too_many_failures;; |
let open_account (initial_pass: passwd) : bank_account = let cur_pass = ref initial_pass in let num_attempt = ref 0 in let cur_balance = ref 0 in let my_bank_account = { update_pass = ( fun old_pass new_pass -> if old_pass <> !cur_pass then let _ = (num_attempt := !num_attempt + 1) in raise wrong_pass else let _ = (num... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f l (a, b, c) = if a = vertex then (b,c) :: l else l in List.fold_left 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) (path: 'a list) (w: weight) : ('a list * weight) = let (cur_node, cur_weight) = node in let path = path @ [cur_node] in let w = w + cur_weight in let visited = cur_node :: visited in if cur_node =... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (path : 'a list) (w : weight) fc sc : ('a list * weight)= let (cur_node, cur_weight) = node in let path = path @ [cur_node] in let w = w + cur_weight in let visited = cur_node :: visited in if cu... |
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 rec get_largest (ls : ('a list * weight) list) (path : ('a list * weight) option) (weight : weight) : ('a list * weight) option = match ls with | [] -> path | x::xs -> let (_, cur_weight) = x in if cur... |
let open_account(initial_pass: passwd) : bank_account = let n = ref 0 and pass = ref initial_pass and count = ref 0 in { update_pass = (fun oldpass -> fun newpass -> if oldpass <> !pass then (count := !count + 1; raise wrong_pass) else (pass := newpass; count := 0)) ; retrieve = (fun pwd -> fun amount -> if !count = 3 ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = (fun (v1,v2,w) acc -> if v1 = vertex then (v2,w)::acc else acc )in List.fold_right f g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let add = (fun (l,wt) (v,w) -> (v::l, wt+w) )in let rec aux_node (v,w) (visited : 'a list) : ('a list * weight) = if (List.exists (fun vis -> vis = v ) visited) then raise Fail else if (v=b) then ([],0) else aux_list (neighbours g v) (v::visited) and au... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (v,w) (visited : 'a list) fc sc : ('a list * weight)= if (List.exists (fun vis -> vis = v ) visited) then fc () else if (v=b) then sc ([],0) else aux_list (neighbours g v) (v::visited) fc sc and aux_list (nodes: ('a * weight) list) (vi... |
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::t -> Some (List.fold_left (fun (l1, w1) (l2, w2) -> if (w2<w1) then (l1, w1) else (l2,w2)) x t);; |
let open_account (p: passwd) : bank_account = let balance = ref 0 in let password = ref p in let attempts = ref 0 in let checkPass (p: passwd): bool = if (!attempts < 3) then if (p = !password) then (attempts := 0; true) else (attempts := !attempts+1; raise wrong_pass) else raise wrong_pass in { update_pass = (fun (old... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = (fun (v1,v2,w) acc -> if v1 = vertex then (v2,w)::acc else acc )in List.fold_right f g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let add = (fun (l,wt) (v,w) -> (v::l, wt+w) )in let rec aux_node (v,w) (visited : 'a list) : ('a list * weight) = if (List.exists (fun vis -> vis = v ) visited) then raise Fail else if (v=b) then ([],0) else aux_list (neighbours g v) (v::visited) and au... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (v,w) (visited : 'a list) fc sc : ('a list * weight)= if (List.exists (fun vis -> vis = v ) visited) then fc () else if (v=b) then sc ([],0) else aux_list (neighbours g v) (v::visited) fc sc and aux_list (nodes: ('a * weight) list) (vi... |
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::t -> Some (List.fold_left (fun (l1, w1) (l2, w2) -> if (w2<w1) then (l1, w1) else (l2,w2)) x t);; |
let open_account (initial_pass: passwd) : bank_account = let acc_data = {balance = ref 0 ; pass = ref initial_pass ; passwd_attempts = ref 0 ; too_many_fails_flag = ref false} in let is_too_many_fails ()= if !(acc_data.passwd_attempts) = 5 then acc_data.too_many_fails_flag := true; in let reset () = (acc_data.passwd_at... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let h = List.filter (fun x -> let (v1,_,_) = x in v1 = vertex) (g.edges) in List.map (fun c -> let (_,v2,w) = c in (v2,w)) h;; let add_to_visited (l:'a list) (x:'a):unit = x::l; ();; |
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_name = fst node in let node_weight = snd node in if (fst node) = b then ([node_name], node_weight) else let x = neighbours g (node_name) in match x with |[] -> rais... |
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 node_name = fst node in let node_weight = snd node in if (fst node) = b then ([node_name], node_weight) else let x = neighbours g (node_name) in match x with |[] -... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let x = find_all_paths g a b in if x = [] then None else let initial_max_path= ([],0) in let rec helper (all_paths:('a list * int) list) (max_path: ('a list * int)) : ('a list * int) option = match all_paths with |[]-> Some (max_path) |h:... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let num_attempts = ref 0 in { update_pass = (fun (oldp:passwd) (newp:passwd) -> if oldp <> !password then let _ = num_attempts := !num_attempts + 1 in raise wrong_pass else let _ = password := newp in num_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let ls = List.fold_left (fun init_list x -> match x with |(v1,v2,w) when v1 = vertex -> (v2,w)::init_list |_ -> init_list) [] g.edges in ls ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then raise Fail else let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (city,w) = node in if city = b && not(List.mem city visited) then ([city],w) else if List.mem city visited then raise Fail else let (ls,wei... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then raise Fail else let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (city,w) = node in if city = b && not(List.mem city visited) then sc ([city],w) else if List.mem city visited then fc () else let sc'... |
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 List.length allpaths = 0 then None else let p = List.sort (fun ((xs,xi):('a list * int)) ((xs,yi):('a list * int)) -> if xi > yi then -5 else if xi = yi then 0 else 5) allpaths in Some(List.nth p ... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let num_attempts = ref 0 in { update_pass = (fun (oldp:passwd) (newp:passwd) -> if oldp <> !password then let _ = num_attempts := !num_attempts + 1 in raise wrong_pass else let _ = password := newp in num_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let ls = List.fold_left (fun init_list x -> match x with |(v1,v2,w) when v1 = vertex -> (v2,w)::init_list |_ -> init_list) [] g.edges in ls ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then raise Fail else let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (city,w) = node in if city = b && not(List.mem city visited) then ([city],w) else if List.mem city visited then raise Fail else let (ls,wei... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then raise Fail else let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (city,w) = node in if city = b && not(List.mem city visited) then sc ([city],w) else if List.mem city visited then fc () else let (ls... |
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 List.length allpaths = 0 then None else let p = List.sort (fun ((xs,xi):('a list * int)) ((xs,yi):('a list * int)) -> if xi > yi then -5 else if xi = yi then 0 else 5) allpaths in Some(List.nth p ... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in {update_pass = (fun old newPassword -> if old = !password then (counter := 0; password := newPassword) else (counter := !counter + 1; raise wrong_pass)); retrieve = (fun pass amount ... |
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) = if (fst node) = b then ([b], (snd node)) else if List.mem (fst node) visited then raise Fail else (let (path, cost) = aux_list (neighbours g (fst node)) ((fst node) :: visit... |
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 ([b], (snd node)) else if List.mem (fst node) visited then fc () else aux_list (neighbours g (fst node)) ((fst node) :: visited) fc (fun (pat... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max paths = match paths with | [] -> None | [(path, weight)] -> Some (path, weight) | (path, weight) :: (path2, weight2) :: tl -> if weight < weight2 then (max ((path2, weight2) :: tl)) else (max ((path, weight) :: tl)) in max (fi... |
let open_account (initial_pass: passwd) : bank_account = let account = ref initial_pass in let balance = ref 0 in let pass_fails = ref 0 in { update_pass = (fun (old_pass:passwd) (new_pass:passwd) -> if !account = old_pass then (account := new_pass; pass_fails := 0 ) else ( pass_fails := !pass_fails + 1; raise wrong_pa... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun ls v -> let (v1, v2, w) = v in if v1 = vertex then (v2,w)::ls else ls) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight : int) : ('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+w) a... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight : int) fc sc : ('a list * weight)= let (n,w) = node in if n = b then sc (visited@[n], weight+w) else if List.mem n visited then fc () else aux_list (neighbours g n) (visited@[n]) (weight+... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | path::paths -> let rec max_weight (cur_max, rest) = match rest with | [] -> Some cur_max | path'::paths' -> let (n',w') = path' in let (n, w) = cur_max in let cur_max' = if w' > w then path' ... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let fail_count = ref 0 in { update_pass = (fun old_p new_p -> match old_p with | _ when old_p = !password -> fail_count := 0; password := new_p | _ -> fail_count := !fail_count + 1; raise wrong_pass ) ; re... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes; edges} = g in List.fold_left (fun neighbour_list edge -> let (v1, v2, w) = edge in if v1 = vertex then (v2, w) :: neighbour_list else neighbour_list ) [] 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 * weight) list = let (n, _) = node in let paths = neighbours g n in aux_list paths visited and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a * weight) list = match nodes with... |
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 * weight) list = let (n, _) = node in let paths = neighbours g n in aux_list paths visited fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a * weight) list... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.