text stringlengths 0 601k |
|---|
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, weight) : 'a * weight) (visited : 'a list) : ('a list * weight) = if node = b then ([node], weight) else if List.mem node visited then raise Fail else let (path, cost) = aux_list (neighbours g node) (node :: visited) in (node ::... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node, weight) : 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if node = b then sc ([node], weight) else if List.mem node visited then fc () else let sc2 = fun (path, cost) -> sc (node :: path, cost + weight) in aux_lis... |
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 | h :: t -> let rec longest_path paths ((longest, max_cost) : 'a list * weight) : 'a list * weight = match paths with | [] -> (longest, max_cost) | (path, cost) :: t -> if ... |
let open_account (initial_pass: passwd) : bank_account = let count = ref 0 in let mypwd = ref initial_pass in let balance = ref 0 in { update_pass = (fun pwd1 pwd2 -> if (pwd1 = !mypwd) then (mypwd := pwd2; count := 0; ) else (count := !count + 1; raise wrong_pass)) ; deposit = (fun pwd x -> if !count >= 5 then raise t... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neighbours_rec edges vertex result = match edges with | [] -> result | (v1, v2, w) :: t -> if v1 = vertex then neighbours_rec t vertex ((v2,w)::result) else neighbours_rec t vertex result in neighbours_rec 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) (totalw: weight): ('a list * weight) = let (v, w) = node in if (List.mem v visited) then raise Fail else if (v = b) then (visited @ [b], totalw + w) else ( aux_list (neighbours g v) ( visited @ [v... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (totalw: weight) fc sc = let (v, w) = node in if (List.mem v visited) then fc () else if (v = b) then sc visited totalw v w else aux_list (neighbours g v) ( visited @ [v] ) (totalw + w) fc sc and... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a): ('a list * weight) option = let rec find_longest list max max_lst: ('a list * weight) option = match list with | [] -> if max = 0 then None else Some (max_lst, max) | (lst, w)::xs -> if w > max then find_longest xs w lst else find_longest xs max max_lst in find_longe... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let counter = ref 0 in let balance = ref 0 in { update_pass = (fun curpass newpass -> if curpass = !password then ( password := newpass; counter :=0; ) else ( counter := !counter + 1; raise wrong_pass) ); retrieve = (fun pass am... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let startswith x = let (fst, _, _) = x in fst = vertex in List.map (fun x -> let (_, snd, thrd) = x in (snd, thrd)) (List.filter startswith 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 (visited@[fst node], snd node) else if List.exists (fun n -> (fst node) = n) visited then raise Fail else aux_list (List.map (fun (a1, w1) -> (a1, w1 ... |
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.exists (fun a -> (fst node) = a) visited then fc () else aux_list (neighbours g (fst node)) ((fst node)::visit... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with |[] -> None |h::tl -> Some (List.fold_left (fun a b -> if (snd b) > (snd a) then b else a) h tl);; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let counter = ref 0 in let balance = ref 0 in { update_pass = (fun curpass newpass -> if curpass = !password then ( password := newpass; counter :=0; ) else ( counter := !counter + 1; raise wrong_pass) ); retrieve = (fun pass am... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let startswith x = let (fst, _, _) = x in fst = vertex in List.map (fun x -> let (_, snd, thrd) = x in (snd, thrd)) (List.filter startswith 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 (List.append visited [fst node], snd node) else if List.exists (fun n -> (fst node) = n) visited then raise Fail else aux_list (List.map (fun (a1, w1)... |
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.exists (fun a -> (fst node) = a) visited then fc () else aux_list (neighbours g (fst node)) ((fst node)::visit... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with |[] -> None |h::tl -> Some (List.fold_left (fun a b -> if (snd b) > (snd a) then b else a) h tl);; |
let open_account (initial_pass: passwd) : bank_account = let (curr_pass : passwd ref ) = ref "" in let (attempts: int ref) = ref 0 in let (balance: int ref) = ref 0 in let check_attempts () = if !attempts >= 5 then raise too_many_failures in let check_neg amt = if (amt < 0) then raise negative_amount in let count_passw... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find_out_neighbours e' acc = match e' with | (v, n, w)::tl when v=vertex -> find_out_neighbours tl ((n,w)::acc) | _::tl -> find_out_neighbours tl acc | [] -> acc in find_out_neighbours 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) (cumul : weight) : ('a list * weight) = let (n,_) = node in if (n=b) then ((path @ [n]), cumul) else aux_list (neighbours g n) visited (path @ [n]) cumul 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 let sc2 = (fun (n',w') -> let (p, cw)= sc (n,w) in ((p @ [n']),cw+w')) in aux_list (neighbours g n) visited fc sc2 and ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec search_longest (paths : ('a list * weight) list) (max_path : 'a list) (max_w : weight) : 'a list * weight = match paths with | [] -> (max_path, max_w) | (path, w) :: tl -> if w >= max_w then search_longest tl path w else search_lo... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = (fun pass_1 pass_2 -> if pass_1 = !password then let _= attempts := 0 in password := pass_2 else let _= attempts := !attempts + 1 in raise wrong_pass); retrieve = (f... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find_nodes n l = match n with |[] -> l |(v1,v2,w)::xs -> if v1 = vertex then find_nodes (xs) ((v2,w)::l) else find_nodes (xs) l in find_nodes 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) (total_weight: int): ('a list * weight) = let (v1,w1) = node in if v1 = b then ((List.rev (v1::visited)), (total_weight+w1)) else if List.mem v1 visited then raise Fail else let 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) (total_weight: int) fc sc : ('a list * weight)= let (v1,w1) = node in if v1 = b then sc ((List.rev (v1::visited)), (total_weight+w1)) else if List.mem v1 visited then fc () else let list_neighbou... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let compare l1 l2 = match l1 with | None -> let (v2, w2) = l2 in Some(v2,w2) | Some(v1,w1) -> let (v2, w2) = l2 in if w2 > w1 then Some (v2, w2) else Some(v1, w1) in List.fold_left compare None (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let init = ref initial_pass in let counter = ref 0 in let amount_in = ref 0 in let updateco passwd = counter := !counter +1; raise wrong_pass in { update_pass = (fun oldp newp-> if !init = oldp then (init := newp ; counter := 0 ) else if (!counter <=5 && !init !=... |
let neighbours g vertex = List.fold_left (fun a (x, y, z) -> if x=vertex then (y,z)::a else a) [] g.edges;; let rec get_nth mylist index = match mylist with | [] -> raise (Failure "empty list") | first::rest -> if index = 0 then first else get_nth rest (index-1) ;; let pair_mode l = if List.length l < 2 then failwith "... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let get_nodes anode= let (s,h) = anode in s in let rec aux_node node visited = let thelist = List.map get_nodes (neighbours g node) in if node = b then [b] else if List.mem node visited then raise Fail else node::(aux_list thelist (node::visited)) and a... |
let find_path' g a b = let rec get_nth mylist index = match mylist with | [] -> raise (Failure "empty list") | first::rest -> if index = 0 then first else get_nth rest (index-1) in let pair_mode l = if List.length l < 2 then failwith "List too small." else let (_ :: no_front) = l in let (_ :: no_back) = List.rev l in l... |
let find_longest_path g a b = let list1= remove_from_right (List.rev(store_sum g a b)) in if list1 = [] then None else let sorted = List.sort compare list1 in let greatestele = List.nth sorted ((List.length sorted) -1) in let index = findversion2 greatestele list1 in let all =find_all_paths g a b in Some (List.nth all ... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let actual_pass = ref initial_pass in let num_err = ref 0 in { update_pass = (fun input1 -> (fun input2 -> if input1 = !actual_pass then (actual_pass :=input2; num_err := 0;) else (incr num_err ; raise wrong_pass; ) )); retrieve= (fun input... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let list = g.edges in List.fold_right (fun triple acc -> let (a,b,c) = triple in if a=vertex then (b,c)::acc else acc) list [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (curr_w : int) : ('a list * weight) = let (x,y) = node in if List.mem x visited then (raise Fail) else ( if x == b then ((visited @ [x], curr_w + y ) ) else ( try aux_list (neighbours g x) (visite... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (curr_w : int) success failure : ('a list * weight) = let (x,y) = node in if List.mem x visited then failure () else ( if x == b then success(node, visited, curr_w) else ( aux_list (neighbours g ... |
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 userPwd = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let correct_password (attempt : passwd) : bool = if (attempt <> !userPwd) then raise wrong_pass else true in let positive_amount (amount : int) = if (amount < 0) then raise negative_a... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let graph_edges = g.edges in let rec make_neighbour_list (edges: ('a * 'a * weight) list) ((vertex: 'a)) : ('a * int) list = match edges with |[] -> [] |x :: xs -> match x with |(w, y, z) when w = vertex -> (y, z) :: make_neighbour_list xs vertex |(_,_,_)... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let endPoint = b in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list) = let (city, _) = node in if (List.mem city visited) then raise Fail else match node with |(x, _) when x = endPoint -> [x] |(w, _) -> w :: aux_list (neighbours g w)... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let fail_case () = raise Fail in let success_case x acc = x :: acc in let endPoint = b in let rec aux_node (node: 'a * weight) (remaining: ('a * weight) list) (visited : 'a list) (acc : 'a list) fc sc : ('a list)= let (city, _) = node in if (List.mem c... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest (list: ('a list * weight) list) (max : ('a list * weight)) : ('a list * weight) option = match list with |[] -> None |x :: [] -> let (_, weight) = x in let (_, maxWeight) = max in if weight > maxWeight then Some x else Som... |
let open_account (initial_pass: passwd) : bank_account = let passW = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = (fun oldPass newPass -> if (oldPass = !passW) then (passW := newPass; attempts := 0) else (attempts := !attempts + 1; raise wrong_pass)); retrieve = (fun pass amt -> if... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let mkList = (fun acc edge -> let (v, o, w) = edge in if (v = vertex) then ((o, w) :: acc) else acc) in List.fold_left mkList [] (g.edges);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (w : weight) : ('a list * weight) = let (name, w2) = node in if (name = b) then (List.append visited [name], w + w2) else aux_list (neighbours g name) (List.append visited [name]) (w+w2) and aux_l... |
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 (name, w) = node in if (name = b) then sc ([name], w) else if not (List.mem name visited) then aux_list (neighbours g name) (List.append visited [name]) fc (fun (p... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec findMax inList bestCombo maxW = match inList with | [] -> bestCombo | (valList, w)::rest -> if (w >= maxW) then (findMax rest (valList, w) w) else findMax rest bestCombo maxW in let ab = findMax (find_all_paths g a b) ([],0) 0 in ... |
let open_account (initial_pass: passwd) : bank_account = let pas = ref initial_pass in let bal = ref 0 in let incorrect = ref 0 in {update_pass = (fun pwo pwn -> if pwo = !pas then (pas := pwn; incorrect := 0 ) else (incorrect := !incorrect + 1; raise wrong_pass)); retrieve= (fun pw i -> if !incorrect > 4 then raise to... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (v1,v2,w) -> (v2, w) ) (List.filter (fun (v1,v2,w) -> v1= vertex) g.edges) exception NoneToGo;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((x,w) as node: 'a * weight) (visited : 'a list) : ('a list * weight) = if x = b then (visited, w) else aux_list (neighbours g x) (visited) w and aux_list (nodes: ('a * weight) list) (visited: 'a list) acc : ('a list * weight) = let rec... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((x,w) as node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if x = b then (sc (x::[], w)) else (if (List.mem x visited) then fc () else aux_list (neighbours g x) (x::visited) fc (fun (t, v) -> sc (x::t, w+v)) ) and aux... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec get_largest (ps: ('a list * weight) list ) ((vis, w) as cur_max): 'a list * weight = match ps with | [] -> cur_max | (visc, wc) :: xs -> if wc > w then get_largest xs (visc, wc) else get_largest xs cur_max in let paths = find_all_... |
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 = (function oldPass -> function newPass -> if oldPass = !password then let _ = (counter := 0) in password := newPass else let _ = (counter := !counter + 1) in raise wro... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges vertex acc = match edges with | [] -> acc | h :: t -> match h with | (v,nei,weight) when v = vertex -> helper t v (acc @ [(nei,weight)]) | (_,_,_) -> helper t vertex acc in helper g.edges vertex [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (start,w) visited = if start = b then ([b],w) else if not (List.mem start visited) then let (path,acc) = aux_list (neighbours g start) (start :: visited) in (start :: path,acc + w) else raise Fail and aux_list (nei_list : ('a * weight) ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (start, w) visited fail success = if start = b then success ([b], w) else if not (List.mem start visited) then aux_list (neighbours g start) (start :: visited) fail (fun (path,acc) -> success (start :: path,acc + w)) else fail () and a... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = find_max (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 attempts = ref 0 in let check_pass pass = if pass = !password && !attempts < 5 then attempts := 0 else if pass = !password && !attempts >= 5 then raise too_many_failures else if (pass <> !password) the... |
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 password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in let check_pass pass = if pass = !password && !attempts < 5 then attempts := 0 else if !attempts >= 5 then raise too_many_failures else if (!attempts < 5) then (attempts := !attempts... |
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 password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in let update_pass (old_password:passwd) (new_password:passwd) = if old_password <> !password then raise wrong_pass else password := new_password in let retrieve (pass:passwd) (money_r... |
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 password = ref initial_pass in let fail = ref 0 in { update_pass = ( fun (old_pass : passwd) -> fun (new_pass : passwd) -> if old_pass = !password then ( fail := 0; password := new_pass) else ( fail := !fail + 1; raise wrong_pass ) ) ; ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f (l : ('a * weight) list) ((v1, v2, w): ('a * 'a * weight)) = if v1 = vertex then List.append l [(v2, w)] 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 ((v2, w): 'a * weight) (visited : ('a * weight) list) : ('a list * weight) = if v2 = b then ( let cum_w = List.fold_left (fun x -> fun (y, z) -> x + z) 0 visited in let l = List.fold_left (fun x -> fun (y, z) -> List.append x [y]) [] vi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((v2, w): 'a * weight) (visited : ('a * weight) list) fc sc : ('a list * weight)= if v2 = b then sc visited else ( let ngb = neighbours g v2 in aux_list ngb visited fc sc ) and aux_list (nodes: ('a * weight) list) (visited: ('a * weigh... |
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 sort_f ((path1, w1): 'a list * weight) ((path2, w2): 'a list * weight) = if w1 = w2 then 0 else if w1 < w2 then 1 else -1 in let sort_paths = List.sort sort_f paths in... |
let open_account (initial_pass: passwd) : bank_account = let bal = ref 0 in let pass = ref initial_pass in let numFailPass = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass:passwd) -> if old_pass = !pass then ( numFailPass := 0; pass := new_pass; ) else ( numFailPass := !numFailPass + 1; raise wrong_pass ) )... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun collectNeighbors path -> let v1,v2,w = path in if v1 = vertex then ( collectNeighbors@[(v2,w)] ) else collectNeighbors ) [] g.edges let notVisitedYetFunction (vertex: 'a) (g: 'a graph) (visitedNodes: 'a list) = List.filter ( fun edge -... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec dfs (vertex: 'a) (path : ('a list * weight)) (visitedNodes: 'a list) : ('a list * weight) = let notVisitedYet = notVisitedYetFunction vertex g visitedNodes in match notVisitedYet with | (nod, totalWeight)::tl -> let node, weight = path in if nod... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec dfs (vertex: 'a) (path: ('a list * weight)) (visitedNodes: 'a list) sc fc = let notVisitedYet = notVisitedYetFunction vertex g visitedNodes in match notVisitedYet with | (nod, totalWeight)::tl -> let node, weight = path in if nod = b then sc (n... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let allPaths = find_all_paths g a b in let rec max f = match f with | [(path1,path2)] -> Some (path1,path2) | (path1, weight1) :: (path2,weight2) :: tl -> if weight1 > weight2 then max ((path1,weight1)::tl) else max ((path2,weight2)::tl) ... |
let open_account (initial_pass: passwd) : bank_account = let old_pass = ref initial_pass in let balance = ref 0 in let counter = ref 0 in {update_pass = (fun pass (new_pass : passwd) : unit -> if (pass = !old_pass) then (old_pass := new_pass) else (counter := !counter + 1; raise wrong_pass)); retrieve = (fun pass amoun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = match g.edges with | [] -> [] | _ -> List.rev (List.fold_left (fun (acc : ('a * weight) list) (our_edge : ('a * 'a * weight)) : ('a * weight) list -> if(first our_edge = vertex) then (List.cons (snd_thd our_edge) 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 (List.mem (fst(node)) (visited)) then raise Fail else aux_list (neighbours g (fst(node))) (fst(node) :: visited) 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) 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 Some (find_path g a b) with Fail -> None;; |
let open_account (initial_pass: passwd) : bank_account = let wrong = ref 0 in let pass = ref initial_pass in let money = ref 0 in { update_pass = (fun input1 input2 -> if input1 = !pass then (wrong := 0; pass := input2) else raise wrong_pass); retrieve = (fun input1 input2 -> if input1 <> !pass then (wrong := !wrong + ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper1 edges vertex t = match edges with | [] -> t ; | (a,b,c)::xs -> if vertex = a then let newt = (b,c)::t in helper1 xs vertex newt else helper1 xs vertex t in helper1 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) = if let o = fst(node) in List.mem o visited then raise Fail else let newvisited = fst(node) :: visited in match node with |(a,0) -> if a = b then ([a],0) else let nodess = ne... |
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 newvisited = fst(node) :: visited in match node with |(a,0) -> if a = b then sc ([a],0) else (let nodess = neighbours g a in let y = aux_list nodess newvisited fc ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let c = find_all_paths g a b in if c = [] then None else let rec helper3 c (n,m) = match c with | [] -> Some (n,m) | (x,w)::xs -> if w>m then helper3 xs (x,w) else helper3 xs (n,m) in helper3 c ([],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 old_pass new_pass -> if old_pass = !pass then let _ = attempts := 0 in pass := new_pass else let _ = attempts := !attempts + 1 in raise wrong_pass); retrieve = (fun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in let f = fun result edge -> match edge with | (v1, v2, weight) -> if v1 = vertex then result @ [(v2, weight)] else result | _ -> result in List.fold_left f [] 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) = 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 failed_attempts = ref 0 in let money = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !password then (failed_attempts := 0; password := new_pass;) else (failed_attempts := !failed_attempts + 1; raise wrong_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun ls (a, b, w) -> if a = vertex then (b, w) :: ls else ls ) [] g.edges;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.