text stringlengths 0 601k |
|---|
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in List.fold_left (fun lst (v1, v2, w) -> if v1 = vertex then (v2, w) :: lst else lst) [] edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((vertex, w): 'a * weight) (visited : 'a list) : ('a list * weight) = if vertex = b then ([vertex], w) else let nears = neighbours g vertex in let news = List.filter (fun (a, _) -> not (List.mem a visited)) nears in let (lst, w') = aux_... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((v, w): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if v = b then sc ([v], w) else let nears = neighbours g v in let news = List.filter (fun (a, _) -> not (List.mem a visited)) nears in aux_list news (v :: visited) fc... |
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::xs -> Some (List.fold_left (fun (vs,w) (vs', w') -> if w > w' then (vs,w) else (vs', w')) x xs);; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let money= ref 0 in let counter = ref 0 in let result ={ update_pass = (fun pas x2-> if pas = !password then(counter := 0; password := x2) else ( counter :=!counter +1; raise wrong_pass) ) ; retrieve = (fun pas i -> if !counter ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let compare (v1,v2,w) v acc = if v1=v then acc @ [(v2,w)] else acc in let rec loop (e: ('a * 'a * weight)list ) (vertex: 'a) acc = match e with |[]->acc |x::xs->loop xs vertex (compare x vertex acc) in let result = loop g.edges vertex [] in result;; |
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) = match node with |(x,w) when x = b -> (visited @ [x], acc+w) |(x,w)-> if List.mem x visited then raise Fail else aux_list (neighbours g x ) (visited @ [x]) (acc+w) and au... |
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 |(x,w) when x = b -> (visited @ [x],(sc w)) |(x,w) -> if List.mem x visited then fc () else aux_list (neighbours g x) (visited @ [x]) fc (fun x-> (sc x... |
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 rec get_max (l:('a list * weight) list) result acc = match l with |[]-> (result, acc) |x::xs -> if snd(x) > acc then get_max xs (fst(x)) (snd(x)) else get_max xs result acc in let result = get_max l [] ... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let status = ref 0 in { update_pass = (fun old_p new_p -> (if old_p = !pass then (pass := new_p; status :=0) else (status := !status + 1; raise wrong_pass))); retrieve = (fun p r -> (if !status > 4 then raise ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper l (a, b, c) = if a = vertex then (b, c) :: l else l in List.fold_left 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) (weightacc : weight): ('a list * weight) = match node with | (a, w) when (List.mem a visited) -> raise Fail | (a, w) when a = b -> (visited@[a], w + weightacc) | (a, w) -> aux_list (neighbours g 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)= match node with | (n, w) when (List.mem n visited) -> fc() | (n, w) when n = b -> sc ([n], w) | (n, w) -> aux_list (neighbours g n) (n::visited) fc (fun (a, b) -> sc (... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper l node lstweight = match l with | [] -> (match lstweight with | 0 -> None | _ -> Some node) | (n, w)::xs -> if w > lstweight then helper xs (n, w) w else helper xs node lstweight in helper (find_all_paths g a b) ([], 0) 0 ;... |
let open_account (initial_pass: passwd) : bank_account = let fails = ref 0 in let the_password = ref initial_pass in let balance = ref 0 in { update_pass = (function password -> if password = !the_password then fun pass -> (the_password := pass; fails := 0) else (fails := !fails +1;raise wrong_pass)); retrieve = (funct... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let v1 = vertex in let f (edge: ('a * 'a * weight)) (li: (string * weight) list): (string * weight) list= let (x,y,z) = edge in if x = v1 then (y,z) :: li else li 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) (total_w: int) : ('a list * weight) = let (v,w) = node in if List.mem v visited then raise Fail else(;; |
let neighbours = neighbours g v in if v=b then (List.rev (v::visited), total_w + w) else (aux_list neighbours (v::visited) (total_w + w)) ) and aux_list (nodes: ('a * weight) list) (visited: 'a list) (total_w: int) : ('a list * weight) = match nodes with |x ::xs -> ( try aux_node x visited total_w with fail -> aux_list... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_w: int) fc sc : ('a list * weight)= let (v,w) = node in if List.mem v visited then fc () else(;; |
let neighbours = neighbours g v in if v=b then sc [v] w else( let sc2 = fun p q -> sc (v::p) (w+q) in aux_list neighbours (v::visited) (total_w + w) fc sc2 ) ) and aux_list (nodes: ('a * weight) list) (visited: 'a list) (total_w: int) fc sc : ('a list * weight) = match nodes with |x ::xs -> ( let (v,w) = x in let fail3... |
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let rec aux_node (node: 'a * weight) (visited : 'a list) (total_w: int) (biglist : ('a list * weight) list ): ('a list * weight) list = let (v,w) = node in if List.mem v visited then raise Fail else(;; |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec find_longest (paths:('a list * weight) list) (longest_path:('a list * weight)): ('a list * weight) = match paths with |x::xs -> ( let (p,w) = x in let (p',w') = longest_path in if w > w' then find_longest xs x else find_longest xs... |
let open_account (initial_pass: passwd) : bank_account = let current_pass = ref initial_pass in let current_balance = ref 0 in let failure_count = ref 0 in { update_pass = (fun (old_pass) (new_pass) -> if String.equal old_pass !current_pass then (current_pass := new_pass ; failure_count := 0 ) else (failure_count := !f... |
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) = if (...) then aux_node (....) else(...) then aux_list (...) and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = notimplemented () in notimplem... |
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 cur_pass = ref initial_pass in let balance: int ref = ref 0 in let num_try: int ref = ref 0 in let check_pass = fun pass -> if !num_try >= 5 then raise too_many_failures else if pass = !cur_pass then num_try := 0 else (num_try := 1 + !num_try; raise wrong_pas... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f (o, n, w) v = if o = vertex then (n, w) :: v else v 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, w): 'a * weight) (visited : 'a list) : ('a list * weight)= if node = b then ([node], w) else if List.mem node visited then ([], 0) else match aux_list (neighbours g node) (node :: visited) with | ([], _) -> ([], 0) | (path, ww) ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((n, w): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if n = b then sc ([n], w) else if List.mem n visited then fc () else aux_list (neighbours g n) (n :: visited) fc (fun (path, ww) -> sc (n :: path, w + ww)) and aux_l... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f = fun res (path, w) -> match res with | None -> Some (path, w) | Some (path1, w1) -> Some (if w > w1 then (path, w) else (path1, w1)) in List.fold_left f None (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let accountPasswd = ref initial_pass in let accountBalance = ref 0 in let counter = ref 0 in { update_pass = (fun pass newPasswd -> if pass = !accountPasswd then (accountPasswd := newPasswd; counter := 0) else (counter := !counter + 1; raise wrong_pass) ); retrie... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x (e1,e2,e3) -> if e1 = vertex then (e2,e3)::x else x) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = match node with | (n1, w1) when n1 = b -> (List.rev (b::visited), !w + w1) | (n2, w2) -> w := !w + w2; if List.mem n2 visited then raise Fail else aux_list ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= match node with | (n1, w1) when n1 = b -> sc (List.rev (b::visited), !w + w1) | (n2, w2) -> w := !w + w2; if List.mem n2 visited then fc () else aux_l... |
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 accountPasswd = ref initial_pass in let accountBalance = ref 0 in let counter = ref 0 in { update_pass = (fun pass newPasswd -> if pass = !accountPasswd then (accountPasswd := newPasswd; counter := 0) else (counter := !counter + 1; raise wrong_pass) ); retrie... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x (e1,e2,e3) -> if e1 = vertex then (e2,e3)::x else x) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = match node with | (n1, w1) when n1 = b -> (List.rev (b::visited), !w + w1) | (n2, w2) -> w := !w + w2; if List.mem n2 visited then raise Fail else aux_list ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= match node with | (n1, w1) when n1 = b -> sc (List.rev (b::visited), !w + w1) | (n2, w2) -> w := !w + w2; if List.mem n2 visited then fc () else aux_l... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let longest = ref ([""], 0) in List.iter (fun (a,b) -> if b > (snd !longest) then longest := (a,b)) (find_all_paths g a b); if !longest = ([""], 0) then None else Some !longest;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = notimplemented();; |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = None;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (fst node = b) then sc ([fst node], snd node ) else if List.mem (fst node) visited then fc () else let suc2 = fun (path,cost) -> (let (path,cost) = aux_list (neighb... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = None;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (fst node = b) then sc ([fst node], snd node ) else if List.mem (fst node) visited then fc () else let suc2 = fun (path,cost) -> (let (path,cost) = aux_list (neighb... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = None;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (fst node = b) then sc ([fst node], snd node ) else if List.mem (fst node) visited then fc () else let suc2 = fun (path,cost) -> (let (path,cost) = aux_list (neighb... |
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 password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (fst node = b) then sc ([fst node], snd node ) else if List.mem (fst node) visited then fc () else let suc2 = fun (path,cost) -> (let (path,cost) = aux_list (neighb... |
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 password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (fst node = b) then sc ([fst node], snd node ) else if List.mem (fst node) visited then fc () else let suc2 = fun (path,cost) -> (let (path,cost) = aux_list (neighb... |
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 password = ref initial_pass in let currentbalance = ref 0 in let currentfailures = ref 0 in { update_pass = (fun (old_pass: passwd) (new_pass: passwd) -> if (!password = old_pass) then ( password := new_pass ; currentfailures := 0; ) else ( currentfailures :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let isolate_from = fun (a,b,c) -> a in let isolate_to = fun (a,b,c) -> b in let isolate_weight = fun (a,b,c) -> c in let folding = fun inputedge emptylist -> if (isolate_from inputedge = vertex) then (isolate_to inputedge, isolate_weight inputedge) :: emp... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if (fst node = b) then ([fst node], snd node ) else if List.mem (fst node) visited then raise Fail else let (path,cost) = aux_list (neighbours g (fst node)) ([fst node]@visi... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if (fst node = b) then sc ([fst node], snd node ) else if List.mem (fst node) visited then fc () else let suc2 = fun (path,cost) -> (let (path,cost) = aux_list (neighb... |
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 pswd = ref initial_pass in let bal = ref 0 in let wrong_count = ref 0 in let not_too_big = (fun b -> if (b > !bal) then raise not_enough_balance else true) in let check_bal = (fun b -> if (b < 0) then raise negative_amount else true) in let check_pass = (fun ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper = (fun a (v1, v2, w) -> a @ [(v2, w)]) in let l1 = List.filter (fun (v1, v2, w) -> (v1 = vertex)) g.edges in List.fold_left helper [] l1 ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let wAcc = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let element = fst(node) in if List.mem element visited then raise Fail else (wAcc := (!wAcc + snd(node)); let l1 = visited @ [element] in if (element = b... |
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 element = fst(node) in if (List.mem element visited) then fc () else let l1 = visited @ [element] in if element = b then sc ([b], snd(node)) else try aux_list (nei... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l1 = find_all_paths g a b in let l2 = List.sort (fun x y -> snd(x) - snd(y)) l1 in let l3 = List.rev l2 in match l3 with | [] -> None | _ -> Some (List.hd l3) ;; |
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 old_pass new_pass -> if (old_pass = !pass) then (pass := new_pass) else (counter := !counter + 1; raise wrong_pass)) ; deposit = (fun p num -> if (!counter < 5) then... |
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) (w: weight) (visited : 'a list) : ('a list * weight) = if node = b then ([b], w) else if List.mem node visited then raise Fail else (let (path, cost) = aux_list (neighbours g node) (node :: visited) in (node :: path, cost + w... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (w: weight) (visited : 'a list) fc sc : ('a list * weight)= 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 :: pa... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(node, w)] -> Some (node, w) | (node1, w1) :: (node2, w2) :: tail -> if w1 >= w2 then max((node1, w1) :: tail) else max((node2, w2) :: tail) in max (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let account = { password = ref initial_pass ; balance = ref 0 ; wrong_pw_count = ref 0 ; } in { update_pass = ( fun initial_pw final_pw -> if initial_pw = !(account.password) then ( account.password := final_pw ; account.wrong_pw_count := 0 ) else ( account.wrong... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun lst edge -> let (v, b, w) = edge in if v = vertex then List.append lst [(b, w)] else List.append lst [] ) [] 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) (totalWeight: int): ('a list * weight) = if (fst node) = b then (List.rev ((fst node)::visited), (totalWeight + (snd node))) else if List.mem (fst node) visited then raise Fail else;; |
let neighbours = neighbours g (fst node) in match neighbours with | [] -> raise Fail | _ -> aux_list neighbours ((fst node)::visited) (totalWeight + (snd node)) and aux_list (nodes: ('a * weight) list) (visited: 'a list) (totalWeight: int): ('a list * weight) = match nodes with | [] -> raise Fail | somenode::rest -> tr... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (totalWeight: int) fc sc : ('a list * weight) = if (fst node) = b then (List.rev ((fst node)::visited), (totalWeight + (snd node))) else if List.mem (fst node) visited then fc () else let neighb ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = List.fold_left ( fun x (node, weight) -> match x with | None -> Some(node, weight) | Some(otherNode, otherWeight) -> if (weight > otherWeight) then Some(node, weight) else Some(otherNode, otherWeight) ) None (find_all_paths g a b) ;; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let wrongpass_count = ref 0 in { update_pass = (fun initial final -> if initial = !(pass) then (pass := final; wrongpass_count := 0) else (wrongpass_count := !(wrongpass_count) + 1; raise wrong_pass) ); retrie... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec find_node node lst = match node with |[] -> lst |(n1, n2, w)::xs -> if n1 = vertex then find_node (xs) ((n2, w)::lst) else find_node (xs) lst in find_node 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) (tweight: int): ('a list * weight) = let (n,w) = node in if n = b then (List.rev (n::visited), (tweight+w)) else if List.mem n visited then raise Fail else;; |
let neighbours = neighbours g n in match neighbours with |[] -> raise Fail |_ -> aux_list neighbours (n::visited) (tweight + w) and aux_list (nodes: ('a * weight) list) (visited: 'a list) (tweight: int): ('a list * weight) = match nodes with |[] -> raise Fail |n::xs -> let (n1,w1) = n in try aux_node (n1,w1) visited tw... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (totalweight: weight) fc sc : ('a list * weight)= let (n, w) = node in if (n = b) then sc (visited@[n], totalweight + w) else if (List.mem n visited) then fc () else aux_list (neighbours g n) (vi... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f (x) (s,w) = match x with | None -> Some(s,w) | Some(maxp, maxw) -> if (w > maxw) then Some(s,w) else Some(maxp, maxw) in List.fold_left f None (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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.