text stringlengths 0 601k |
|---|
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find graph = match graph.edges with | [] -> [] | (v1,v2,w) :: tl -> if v1 = vertex then (v2 , w ) :: find {nodes = g.nodes; edges = tl } else find { nodes = g.nodes; edges = tl } in find g;; |
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 (v2,w) = node in if v2 = b then ([v2],w) else if List.mem v2 visited then raise Fail else let ( path, w2 ) = aux_list (neighbours g v2) ( v2 :: visited ) in ( v2 :: path... |
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 c = ref 0 in let balance = ref 0 in let password = ref initial_pass in { update_pass = (fun oldpass newpass -> if ( oldpass = !password) then (c := 0; password := newpass) else ( c := !c + 1; raise wrong_pass ) ); retrieve = ( fun pw output -> if ( !c >= 5) t... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find graph = match graph.edges with | [] -> [] | (v1,v2,w) :: tl -> if v1 = vertex then (v2 , w ) :: find {nodes = g.nodes; edges = tl } else find { nodes = g.nodes; edges = tl } in find g;; |
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 (v2,w) = node in if v2 = b then ([v2],w) else if List.mem v2 visited then raise Fail else let ( path, w2 ) = aux_list (neighbours g v2) ( v2 :: visited ) in ( v2 :: path... |
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,w) = node in if v2 = b then sc([v2],w) else if List.mem v2 visited then fc () else aux_list (neighbours g v2) ( v2 :: visited) fc (fun ( list, weight) -> sc ( ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max list = match list with | [] -> None | [(v,w)] -> Some (v,w) | (v1,w1) :: (v2,w2) :: tl -> if w1 >= w2 then max ((v2,w2) ::rest) else max ((v1,w1) :: rest) in max (find_all_paths g a b) *);; |
let open_account (initial_pass: passwd) : bank_account = let c = ref 0 in let balance = ref 0 in let password = ref initial_pass in { update_pass = (fun oldpass newpass -> if ( oldpass = !password) then (c := 0; password := newpass) else ( c := !c + 1; raise wrong_pass ) ); retrieve = ( fun pw output -> if ( !c >= 5) t... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find graph = match graph.edges with | [] -> [] | (v1,v2,w) :: tl -> if v1 = vertex then (v2 , w ) :: find {nodes = g.nodes; edges = tl } else find { nodes = g.nodes; edges = tl } in find g;; |
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 (v2,w) = node in if v2 = b then ([v2],w) else if List.mem v2 visited then raise Fail else let ( path, w2 ) = aux_list (neighbours g v2) ( v2 :: visited ) in ( v2 :: path... |
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,w) = node in if v2 = b then sc([v2],w) else if List.mem v2 visited then fc () else aux_list (neighbours g v2) ( v2 :: visited) fc (fun ( list, weight) -> sc ( ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max allpath = match allpath with | [] -> None | [(v,w)] -> Some (v,w) | (v1,w1) :: (v2,w2) :: tl -> if w1 <= w2 then max ((v2,w2) :: tl) else max ((v1,w1) :: tl) in max (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let c = ref 0 in let balance = ref 0 in let password = ref initial_pass in { update_pass = (fun oldpass newpass -> if ( oldpass = !password) then (c := 0; password := newpass) else ( c := !c + 1; raise wrong_pass ) ); retrieve = ( fun pw output -> if ( !c >= 5) t... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find graph = match graph.edges with | [] -> [] | (v1,v2,w) :: tl -> if v1 = vertex then (v2 , w ) :: find {nodes = g.nodes; edges = tl } else find { nodes = g.nodes; edges = tl } in find g;; |
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 (v2,w) = node in if v2 = b then ([v2],w) else if List.mem v2 visited then raise Fail else let ( path, w2 ) = aux_list (neighbours g v2) ( v2 :: visited ) in ( v2 :: path... |
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,w) = node in if v2 = b then sc([v2],w) else if List.mem v2 visited then fc () else aux_list (neighbours g v2) ( v2 :: visited) fc (fun ( list, weight) -> sc ( ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max allpath = match allpath with | [] -> None | [(v,w)] -> Some (v,w) | (v1,w1) :: (v2,w2) :: tl -> if w1 <= w2 then max ((v2,w2) :: tl) else max ((v1,w1) :: tl) in max (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let amount = ref 0 in let pass = ref initial_pass in let count = ref 0 in { update_pass = (fun old_pass -> fun new_pass -> if !count > 4 then if old_pass <> !pass then (count := !count +1; raise wrong_pass) else (pass := new_pass; count := 0) else if old_pass <> ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun nbs edge -> let (v1,v2,w) = edge in if v1 = vertex then nbs @ [(v2,w)] else nbs) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (vertex: 'a ) (visited : 'a list) (sum : int): ('a list * weight) = match neighbours g vertex with | [] -> raise Fail | [(v,w)] -> (if v = b then (visited @ [v],sum + w) else if List.mem v visited then raise Fail else aux_node v (visite... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (vertex: 'a ) (visited : 'a list) (sum : int): ('a list * weight) = match neighbours g vertex with | [] -> raise Fail | [(v,w)] -> (if v = b then (visited @ [v],sum + w) else if List.mem v visited then raise Fail else aux_node v (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 | lists -> Some(List.hd (List.sort (fun x y -> let (_,w1) = x and (_,w2) = y in if w1 < w2 then 1 else if w1 > w2 then -1 else 0) lists)) ;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let current_balance = ref 0 in let wrong_password_trials = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> ( if (old_pass = ! password) then (password := new_pass; wrong_password_trials := 0) else ((wrong_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes = nodes_list; edges = edge_list} = g in ( List.fold_left (fun listy -> fun (a, b, c) -> (if vertex = a then List.append listy [(b, c)] else List.append listy []) ) [] edge_list) ;; let rec is_visited (element: 'a) (element_list : 'a list) : boo... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nei = neighbours g a in let rec aux_node ((arbitrary, weight): 'a * weight) (visited : 'a list) (acc_final) (acc_weight): ('a list * weight) = if arbitrary = b then (acc_final @ [arbitrary] , acc_weight + weight) else ( if (is_visited arbitrary visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let nei = neighbours g a in let rec aux_node ((arbitrary, weight): 'a * weight) (visited : 'a list) (acc_final) (acc_weight) fc sc: ('a list * weight) = if arbitrary = b then sc (acc_final @ [arbitrary] , acc_weight + weight) else ( if (is_visited arbi... |
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 helper (find_all_paths g a b) None 0 ;; |
let open_account (initial_pass: passwd) : bank_account = let curr_pass = ref initial_pass in let num_attempt = ref 0 in let balance = ref 0 in { update_pass = (fun prev_pass new_pass -> if (compare !curr_pass prev_pass == 0) then (num_attempt := 0; curr_pass := new_pass ) else (num_attempt := (!num_attempt +1); raise w... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let list_edges = List.filter (fun (a,b,c) -> compare a vertex == 0) (g.edges) in List.fold_right (fun (a,b,c) y -> [(b,c)] @ y) 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 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) : ('a list * weight) = if (List.length (List.filter (fun x -> compare x (fst(node)) == 0) visited) == 0) then aux_list (neighbours g (fst(node))) ([fst(node)] @ visited) else aux_list (neighbours ... |
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 curr_pass = ref initial_pass and counter = ref 0 and balance = ref 0 in { update_pass = (fun (old_pass: passwd) (new_passwd: passwd) -> if old_pass = !curr_pass then (curr_pass := new_passwd; counter := 0) else (counter := !counter + 1; raise wrong_pass())); ... |
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 check_pswd pswd enter_pswd af skip = if (not skip) && !af >= 5 then raise too_many_failures else if enter_pswd = !pswd then (af := 0; ()) else (af := !af + 1; raise wrong_pass ) let lt_zero amnt = if amnt < 0 then raise negative_amount else ();; |
let open_account (initial_pass: passwd) : bank_account = let pswd = ref initial_pass in let bal = ref 0 in let auth_fail = ref 0 in { update_pass = (fun e_pass new_pass -> (check_pswd pswd e_pass auth_fail true; pswd := new_pass; ()) ); deposit = (fun e_pass amnt -> check_pswd pswd e_pass auth_fail false; lt_zero amnt;... |
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);; |
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 ex = {nodes = ["a"; "b"]; ... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper edges a endpoint path_list fw = if a = endpoint then (path_list, fw) else let useful_edges = get_edges edges a in let remaining_edges = rm_node_paths edges a in let rec try_all ue = match ue with | [] -> raise Fail | (_v1, v2, w) :: xt ->... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper edges a endpoint path_list fw failure = if a = endpoint then (path_list, fw) else let useful_edges = get_edges edges a in let remaining_edges = rm_node_paths edges a in let rec try_all ue = match ue with | [] -> failure () | (_v1, v2, w)... |
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 Some (List.fold_left (fun (mnp, ml) (np, l) -> if ml < l then (np, l) else (mnp, ml)) ([], 0) paths );; |
let open_account (initial_pass: passwd) : bank_account = let current_pass = ref initial_pass in let password_tries = ref 0 in let balance = ref 0 in { update_pass = (fun old_pass new_pass -> if not (old_pass = !current_pass) then (password_tries := !password_tries + 1; raise wrong_pass) else (password_tries := 0; curre... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l acc = match l with | [] -> acc | x :: xs -> let (v1,v2,w) = x in if v1 = vertex then helper xs ((v2,w) :: acc) else helper xs acc in helper 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) (accW: int) : ('a list * weight) = let (v2,w) = node in if (List.exists (fun x -> x=v2) visited) then raise Fail else aux_list (neighbours g v2) (v2 :: visited) (accW + w) 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) (accW) (fc) (sc) : ('a list * weight)= let (v2,w) = node in if (List.exists (fun x -> x=v2) visited) then fc () else aux_list (neighbours g v2) (v2 :: visited) (accW + w) fc sc and aux_list (node... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper l res = match l with | [] -> res | x :: xs -> let (_, w1) = x in let (_, w2) = res in if (w1 > w2) then helper xs x else helper xs res in let paths = find_all_paths g a b in if paths = [] then None else Some (helper paths (... |
let open_account (initial_pass: passwd) : bank_account = let passwrd = ref initial_pass in let counter = ref 0 in let balance = ref 0 in { update_pass = (fun input update -> if (input = !passwrd) then (passwrd := update; counter := 0) else (counter := !counter + 1; raise wrong_pass)); retrieve = (fun input num -> if (!... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes;edges} = g in List.fold_left (fun acc (v1, v2, w) -> if v1 = vertex then (v2,w)::acc else acc) [] 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 (v,w) = node in if v = b then ([v] , w) else if List.mem v visited then raise Fail else (let (path , cost) = aux_list (neighbours g v) (v :: visited) in (v :: path, cost... |
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 v = b then sc ([v], w) else if List.mem v visited then fc () else aux_list (neighbours g v) (v :: visited) fc (fun (path, cost) -> sc (v :: path... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max path_list = match path_list with | [] -> None | [(path,weight)] -> Some (path,weight) | (path1,weight1)::(path2,weight2)::tail -> if weight1 >= weight2 then max ((path1,weight1)::tail) else max ((path2,weight2)::tail) in max (... |
let message = "Wrong Password.";; |
let open_account (initial_pass: passwd) : bank_account = let accName = ref initial_pass in let accBalance = ref 0 in let wrong_count = ref 0 in { update_pass = (fun a b -> if !wrong_count >= 5 && not (!accName = a) then raise wrong_pass else if not (!accName = a) then begin wrong_count := !wrong_count + 1; raise wrong_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in List.fold_left (fun base v -> let (v1, v2, w) = v in if v1 = vertex then base@[(v2, w)] else base) [] 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 (v, w) = node in let node_neighbours = neighbours g v in if v = b then ([b], w) else if List.mem v visited then raise Fail else (let path, w1 = aux_list (node_neighbours... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let f = (fun () -> raise Fail) in let s = (fun a -> a) in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v, w) = node in let node_neighbours = neighbours g v in if v = b then sc ([b], w) else if List.mem v vis... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_path = find_all_paths g a b in let biggest_weight = ref 0 in let rec the_path paths s c = match paths with | Some [] -> if s = [] then None else List.hd s | Some (h::xs) -> let (list, w) = h in if w > (c) then the_path (Some xs) (... |
let open_account (initial_pass: passwd) : bank_account = let passwd_r = ref initial_pass in let cur_balance = ref 0 in let counter = ref 0 in {update_pass = (fun input_passwd new_passwd -> if input_passwd = !passwd_r then (counter := 0; passwd_r := new_passwd) else (counter := !counter+1; raise wrong_pass)); deposit = ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1,v2,w) -> if v1=vertex then acc @ [(v2,w)] else acc) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (n,w) = node in if n=b then ([n],w) else if not (List.mem n visited) then let (p,c)=aux_list (neighbours g n) (visited@[n]) in (n::p,c+w) else raise Fail and aux_list (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)= let (n,w) = node in if n=b then sc ([n],w) else if not (List.mem n visited) then let sc_cal = fun (p,c) -> (sc (n::p,c+w)) in aux_list (neighbours g n) (visited@[n]) f... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_one all longest = match all with |[] -> Some longest |(l2,w2) :: remaining -> let (l1,w1)=longest in if w2>w1 then let longest = (l2,w2) in find_one remaining longest else find_one remaining longest in match find_all_paths g ... |
let open_account (initial_pass: passwd) : bank_account = let passwd_r = ref initial_pass in let cur_balance = ref 0 in let counter = ref 0 in {update_pass = (fun input_passwd new_passwd -> if input_passwd = !passwd_r then (counter := 0; passwd_r := new_passwd) else (counter := !counter+1; raise wrong_pass)); deposit = ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1,v2,w) -> if v1=vertex then acc @ [(v2,w)] 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) acc : ('a list * weight) = let (n,w) = node in if n=b then (visited@[n],w+acc) else if not (List.mem n visited) then aux_list (neighbours g n) (visited@[n]) (acc+w) else raise Fail and aux_list (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)= let (n,w) = node in if n=b then sc ([n],w) else if not (List.mem n visited) then let sc_cal = fun (p,c) -> (sc (n::p,c+w)) in aux_list (neighbours g n) (visited@[n]) f... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_one all longest = match all with |[] -> Some longest |(l2,w2) :: remaining -> let (l1,w1)=longest in if w2>w1 then let longest = (l2,w2) in find_one remaining longest else find_one remaining longest in match find_all_paths g ... |
let makePassword(initial) = let passwordMethods = ref initial in { set = (:=) passwordMethods ; check = ( fun pass -> pass = !passwordMethods); } let money() = let amount = ref 0 in { increase = (fun toadd -> amount := (!amount + toadd)); decrease = (fun todecrease -> amount := (!amount - todecrease)); get = (fun () ->... |
let open_account (initial_pass: passwd) : bank_account = let b = money() in let p = makePassword(initial_pass) in let t = attempt() in {update_pass = (fun (oldp:passwd) (newp:passwd) -> if p.check(oldp) then (p.set(newp); t.reset()) else (t.increment(); raise wrong_pass)); retrieve = (fun (pass: passwd) (amt : int) -> ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edge list = match edge with | ( a,b,c) :: xs -> if a = vertex then ( helper xs (List.append list [(b,c)])) else (helper xs list) | [] -> list in helper 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 (n,w) = node in if List.mem n visited then raise Fail else if n = b then (List.rev (n::visited) , sum + w) else aux_list (neighbours g n) (n:: visited) (sum +w... |
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 (n,w) = node in if List.mem n visited then fc() else if n = b then sc (List.rev (n::visited) , sum + w) else aux_list (neighbours g n) (n:: visited) (su... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper(all : ('a list * weight) list) (longest : 'a list) (maxcost: int) = match all with | [] -> if longest = [] then None else Some (longest,maxcost) | (l,w) ::xs-> if (w > maxcost) then helper xs l w else helper xs longest maxc... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let attempts = ref 0 in let balance = ref 0 in { update_pass = (fun try_pass new_pass -> if try_pass = !pass then (pass := new_pass; attempts := 0) else (attempts := !attempts + 1; raise wrong_pass)); retrieve = (fun try_pass cash -... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper_n edges v = match edges with | [] -> [] | (a,b,c)::xs -> if a = v then (b,c)::(helper_n xs v) else (helper_n xs v) in helper_n 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 List.mem (fst node) visited then raise Fail else if (fst node) = b then ([(fst node)], snd node) else ((fst node)::(fst (aux_list (neighbours g (fst node)) ((fst node)::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 : ('a list * weight)= notimplemented () and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = notimplemented () in notimplemented () let rec sum_weights g... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest all_paths curr_weight path = match all_paths with | [] -> if curr_weight = (-1) then None else Some path | x::xs -> if (snd x) >= curr_weight then longest xs (snd x) x else longest xs curr_weight path in longest (find_all_... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let money = ref 0 in let login_attempts = ref 0 in { update_pass = (fun old_password new_password -> if old_password = !password then (login_attempts := 0; password := new_password) else (login_attempts := !login_attempts+1; rai... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x -> fun (v1, v2, w) -> if (v1=vertex) then x@[(v2, w)] else x) [] 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) (cost : int) : ('a list * weight) = let (alpha, value) = node in if(alpha = b) then (visited@[b], cost + value) else if (List.mem alpha visited) then raise Fail else let new_visited = visited@[alp... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (cost : int) fc sc : ('a list * weight)= let (alpha, value) = node in if(alpha = b) then sc (visited@[b], cost + value) else if (List.mem alpha visited) then fc () else let new_visited = visited@... |
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 helper now next count = match next with | [] -> Some now | (alpha, value)::xs -> if (value > count) then helper (alpha, value) xs value else helper now xs count in match all_paths with | [] ... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let password_count = ref 0 in let passwordChecker input f = if(input = !password) then ( password_count := 0; f ()) else( password_count := !password_count +1; raise wrong_pass) in let attemptChecker input... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (a,b,weight) -> if(a = vertex) then (b, weight) :: acc else acc) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (id,weight) = node in if (id = b) then ([b], weight) else if List.mem id visited then raise Fail else( let (nodesOfPath, totalWeight) = aux_list (neighbours g id) (id ::... |
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 (id, weight) = node in if(id = b) then sc ([b], weight) else if List.mem id visited then fc () else aux_list (neighbours g id) (id :: visited) fc (fun (nodesOfPath... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max_path allPaths = match allPaths with |[] -> None |[(path, totalWeight)] -> Some (path, totalWeight) |head :: tail -> ( let head_of_tail :: tail_of_tail = tail in let (id1, weight1) = head in let (id2, weight2) = head_of_tail in... |
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 pwd new_password -> if pwd = !password then (attempts := 0; password := new_password) else (attempts := !attempts + 1; raise wrong_pass)); deposit = (fun pwd am... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper graph = let l = graph.edges in match l with | [] -> [] | (v1, v2, w) :: tl -> if v1 <> vertex then helper {nodes = graph.nodes; edges = tl} else (helper {nodes = graph.nodes; edges = tl}) @ [(v2,w)] in helper g;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (visited : 'a list) (sum : int) : ('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 { update_pass = (fun pwd new_password -> if pwd = !password then (attempts := 0; password := new_password) else (attempts := !attempts + 1; raise wrong_pass)); deposit = (fun pwd am... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper graph = let l = graph.edges in match l with | [] -> [] | (v1, v2, w) :: tl -> if v1 <> vertex then helper {nodes = graph.nodes; edges = tl} else (helper {nodes = graph.nodes; edges = tl}) @ [(v2,w)] in helper g;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.