text stringlengths 0 601k |
|---|
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths g a b in if all_paths = [] then None else let rec helper l path_max w_max = match l with | head :: rest -> (let p,w = head in if w > w_max then helper rest p w else helper rest path_max w_max) | [] -> Some (... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let remain = ref 5 in if !remain > 0 then { update_pass = (fun a (new_pass:passwd) -> if a = !pass then pass := new_pass else raise wrong_pass; decr remain); retrieve = (fun a (x:int) -> if a = !pass then if x... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let check (result: ('a * weight) list) (m: 'a * 'a * weight) = let (a,b,c) = m in if a = vertex then (b,c)::result else result in List.fold_left check [] 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 (n, w) = node in if n = b then (List.append visited [n], cost+w) else if neighbours g n = [] then raise Fail else if List.exists (fun x -> x= n) visited then r... |
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 (n, w) = node in if n = b then sc visited n cost w else if neighbours g n = [] then fc () else if List.exists (fun x -> x= n) visited then fc () else au... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let path_list = (find_all_paths g a b) in if path_list=[] then None else let compare = fun path1 path2 -> let (_,c)=path1 in let (_,d)=path2 in if c<=d then path2 else path1 in let result = (List.fold_left compare ([], 0) path_list) in So... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let failed_attempts = ref 0 in { update_pass = (fun (old_pass : passwd)(new_pass : passwd) -> if (old_pass = !pass) then (pass := new_pass ; failed_attempts := 0 ) else (failed_attempts := !failed_attempts + 1... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let is_neighbor (v1, v2, d) = (v1 = vertex) in let get_neighbor (v1, v2, d) = (v2, d) in List.map (get_neighbor)(List.filter is_neighbor g.edges);; |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = notimplemented ();; |
let find_all_paths (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) list = let rec get_path_weight lst = let get_edge x y = List.hd (List.filter (fun (v1, v2, _) -> v1 = x && v2 = y) g.edges) in let get_edge_weight (edge : (string * string * weight)) = match edge with | (_, _, w) -> w in match lst with [] | [_] -> 0 ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths = find_all_paths g a b in if List.length all_paths = 0 then None else let longest = ref ([],0) in let get_weight (path : 'a list * weight) = match path with | (l , w) -> w in List.iter (fun p -> if (get_weight p) > get_weigh... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let acc = { update_pass = (fun p1 p2 -> if p1 = !password then (counter:=0;password:=p2) else (counter:= !counter + 1; raise wrong_pass) ); retrieve = (fun p i -> if !counter < 5 the... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let out_neighbours = [] in let edges = g.edges in let get_v1 (x: ('a * 'a * weight)) = let (v1,_,_) = x in v1 in let get_v2_w (x: ('a * 'a * weight)) = let (_,v2,w) = x in (v2,w) in let rec filter (e: ('a * 'a * weight) list) (v: 'a) (acc : ('a * weight) ... |
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 a1 = fst(node) in let w1 = snd(node) in if a1 = b then ([a1],w1) else if List.mem a1 visited then raise Fail else let (path, w2) = aux_list (neighbours g a1) (a1::visite... |
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 a1 = fst(node) in let w1 = snd(node) in if a1 = b then sc ([a1],w1) else if List.mem a1 visited then fc () else aux_list (neighbours g a1) (a1::visited) fc (fun (p... |
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 path_max paths = match paths with | [] -> None | x :: xs -> let w = snd(x) in begin match path_max xs with | None -> Some x | Some m -> let w1 = snd(m) in if w < w1 then Some m else Some x e... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let acc = { update_pass = (fun p1 p2 -> if p1 = !password then (counter:=0;password:=p2) else (counter:= !counter + 1; raise wrong_pass) ); retrieve = (fun p i -> if !counter < 5 the... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let out_neighbours = [] in let edges = g.edges in let get_v1 (x: ('a * 'a * weight)) = let (v1,_,_) = x in v1 in let get_v2_w (x: ('a * 'a * weight)) = let (_,v2,w) = x in (v2,w) in let rec filter (e: ('a * 'a * weight) list) (v: 'a) (acc : ('a * weight) ... |
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 a1 = fst(node) in let w1 = snd(node) in if a1 = b then ([a1],w1) else if List.mem a1 visited then raise Fail else let (path, w2) = aux_list (neighbours g a1) (a1::visite... |
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 a1 = fst(node) in let w1 = snd(node) in if a1 = b then sc ([a1],w1) else if List.mem a1 visited then fc () else aux_list (neighbours g a1) (a1::visited) fc (fun (p... |
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 path_max paths = match paths with | [] -> None | x :: xs -> let w = snd(x) in begin match path_max xs with | None -> Some x | Some m -> let w1 = snd(m) in if w < w1 then Some m else Some x e... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 and count = ref 0 and pass = ref initial_pass in { update_pass = (fun o_pwd n_pwd -> if o_pwd <> !pass then (count := !count + 1; raise wrong_pass) else (pass := n_pwd; count := 0)) ; retrieve = (fun pwd amount -> if !count >= 5 then raise too... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun neighbors edge -> let (v,v2,w) = edge in if v = vertex then neighbors @ [(v2,w)] else neighbors ) [] 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): ('a list * weight) = let (v2,w) = node in if v2 = b then (visited@[b],w +total) else if List.mem v2 visited then raise Fail else aux_list (neighbours g v2) (visited@[v2]) (total +... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (sum:weight) fc sc : ('a list * weight) = let (nod,w)=node in if nod = b then sc (visited @ [b]), (sum + w) else if (List.mem nod visited) then fc () else aux_list (neighbours g nod) (visited @ [... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | l -> 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 )l) );; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let count_mistake = ref 0 in let bala = ref 0 in { update_pass = (fun x y -> if x = !pass then (pass := y; count_mistake := 0) else (count_mistake := !count_mistake +1; raise wrong_pass) ) ; retrieve= (fun x a -> if x = !pass && !co... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get1 (elst:('a * 'a * weight)) = let (v1,_,_) = elst in v1 in let get2w (elst:('a * 'a * weight)) = let (_,v2,w) = elst in (v2,w) in let check acc lst = let v1 = get1 lst in let n = get2w lst in if v1 = vertex then (n::acc) else acc in List.fold_left ... |
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 (v1,w) = node in if List.mem v1 visited then raise Fail else if v1 = b then (visited @ [v1], w) else (fst(aux_list (neighbours g v1) (visited @[v1])), snd(aux_list (neig... |
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 (v1,w1) = node in if List.mem v1 visited then fc() else if v1 = b then sc ([v1],w1) else aux_list (neighbours g v1) (v1::visited) fc (fun (path, cost) -> sc (v1::p... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_ways = find_all_paths g a b in let max (acc: ('a list * weight)) (lst :('a list * weight)): ('a list * weight) = if snd (lst) > snd(acc) then lst else acc in match all_ways with | [] -> None | _ -> Some (List.fold_left max ([],0) ... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let count_mistake = ref 0 in let bala = ref 0 in { update_pass = (fun x y -> if x = !pass then (pass := y; count_mistake := 0) else (count_mistake := !count_mistake +1; raise wrong_pass) ) ; retrieve= (fun x a -> if x = !pass && !co... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get1 (elst:('a * 'a * weight)) = let (v1,_,_) = elst in v1 in let get2w (elst:('a * 'a * weight)) = let (_,v2,w) = elst in (v2,w) in let check acc lst = let v1 = get1 lst in let n = get2w lst in if v1 = vertex then (n::acc) else acc in List.fold_left ... |
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 (v1,w) = node in if List.mem v1 visited then raise Fail else if v1 = b then (visited @ [v1], w) else (fst(aux_list (neighbours g v1) (visited @[v1])), snd(aux_list (neig... |
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 (v1,w1) = node in if List.mem v1 visited then fc() else if v1 = b then sc ([v1],w1) else aux_list (neighbours g v1) (v1::visited) fc (fun (path, cost) -> sc (v1::p... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_ways = find_all_paths g a b in let max (acc: ('a list * weight)) (lst :('a list * weight)): ('a list * weight) = if snd (lst) > snd(acc) then lst else acc in match all_ways with | [] -> None | _ -> Some (List.fold_left max ([],0) ... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let count_mistake = ref 0 in let bala = ref 0 in { update_pass = (fun x y -> if x = !pass then (pass := y; count_mistake := 0) else (count_mistake := !count_mistake +1; raise wrong_pass) ) ; retrieve= (fun x a -> if x = !pass && !co... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get1 (elst:('a * 'a * weight)) = let (v1,_,_) = elst in v1 in let get2w (elst:('a * 'a * weight)) = let (_,v2,w) = elst in (v2,w) in let check acc lst = let v1 = get1 lst in let n = get2w lst in if v1 = vertex then (n::acc) else acc in List.fold_left ... |
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 (v1,w) = node in if List.mem v1 visited then raise Fail else if v1 = b then (visited @ [v1], w) else (fst(aux_list (neighbours g v1) (visited @[v1])), snd(aux_list (neig... |
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 (v1,w1) = node in if List.mem v1 visited then fc() else if v1 = b then sc ([v1],w1) else aux_list (neighbours g v1) (v1::visited) fc (fun (path, cost) -> sc (v1::p... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_ways = find_all_paths g a b in let max (acc: ('a list * weight)) (lst :('a list * weight)): ('a list * weight) = if snd (lst) > snd(acc) then lst else acc in match all_ways with | [] -> None | _ -> Some (List.fold_left max ([],0) ... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let fail_cnt = ref 0 in let cur_balance = ref 0 in { update_pass = ( fun oldpass newpass -> if oldpass = !pass then (pass := newpass; fail_cnt := 0) else (fail_cnt := (!fail_cnt + 1); raise wrong_pass) ); deposit = ( fun pwd amount ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec all_neighbours (es: (('a * 'a * weight) list)) (cur: 'a) (nbs: (('a * weight) list)) = match es with | [] -> nbs | x::xs -> let (v1, v2, w) = x in if v1 = cur then all_neighbours xs cur ((v2, w)::nbs) else all_neighbours xs cur nbs in let {nodes; ... |
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 ([],0) else aux_list (neighbours g v) visited and aux_list (nodes: ('a * weight) list) (visited: 'a list) : ('a list * weight) = match nod... |
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 ([], 0) else aux_list (neighbours g v) (v::visited) fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a... |
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 rec long_from_list li (max_l, max_w) = match li with | [] -> (max_l, max_w) | (l, w)::xs -> if max_w < w then long_from_list xs (l,w) else long_from_list xs (max_l, max_w) in match all_path wit... |
let wrong_pw = fun c -> c := !c + 1; raise wrong_pass ;; |
let open_account (initial_pass: passwd) : bank_account = let counter = ref 0 in let pw = ref initial_pass in let balance = ref 0 in { update_pass = (fun old_pw new_pw -> if old_pw = !pw then begin pw := new_pw; counter := 0 end else wrong_pw counter); retrieve = (fun p m -> if !counter >= 5 then raise too_many_failures... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let e_list = List.filter (fun x -> let (x1, _, _) = x in x1 = vertex) g.edges in List.map (fun (a,b,c) -> (b,c)) e_list ;; let add_end (a: 'a) (b: 'a list) : ('a list) = List.rev (a :: (List.rev b)) ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = match node with | (n1,n2) when n1 = b -> ((add_end n1 visited),n2) | (n1,n2) -> if List.mem n1 visited then raise Fail else let n = neighbours g n1 in let (p,w) = 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) = match node with | (n1, n2) when n1 = b -> sc ([n1], n2) | (n1, n2) -> if List.mem n1 visited then fc () else let n = neighbours g n1 in let v = n1::visited in aux_list... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let p = find_all_paths g a b in match p with | [] -> None | x :: xs -> Some (sort p) ;; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let funds = ref 0 in let attempts = ref 0 in { update_pass = (fun pass1 pass2 -> if (String.equal !pass pass1) then (pass := pass2; attempts := 0;) else (attempts := !attempts + 1; raise (wrong_pass))); retrieve = (fun password amou... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun (output : ('a * weight) list) (n1,n2,w) -> if (compare n1 vertex) == 0 then List.append output [(n2, w)] else output) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let path = ref [a] in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if not (List.mem (fst(node)) (visited)) then (path := fst(node)::!path; w:=snd(node) + !w; if fst(node) == b then (!path, !w) else try... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let w = ref 0 in let path = ref [a] in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if not (List.mem (fst(node)) (visited)) then (path := fst(node)::!path; w:=snd(node) + !w; if fst(node) == b then sc (!path, !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 current_balance=ref 0 in let current_p= ref initial_pass in let wrong_p = ref 0 in let attempts() = if !wrong_p>5 then begin raise too_many_failures end else if !wrong_p<=5 then raise wrong_pass in let check_pass = fun n -> if (n= !current_p) then true else b... |
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 current_balance=ref 0 in let current_p= ref initial_pass in let wrong_p = ref 0 in let attempts() = if !wrong_p>5 then begin raise too_many_failures end else if !wrong_p<=5 then raise wrong_pass in let check_pass = fun n -> if (n= !current_p && !wrong_p<5) th... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun x-> fun (v1, v2, w) -> if v1=vertex then (v2, w)::x 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) : ('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 initial_pass = ref initial_pass in let balance = ref 0 in let lock_count = ref 0 in let incr_lock_count() = lock_count := !lock_count + 1; raise wrong_pass; in let update_pass (old_pass: passwd) (new_pass: passwd) = if old_pass <> !initial_pass then incr_lock... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = ( let f g edge = let (a,b,w) = edge in if a == vertex then (b, w) :: g else g 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) : ('a list * weight) = let (nn,w) = node in if List.mem nn visited then raise Fail else if nn == b then (nn :: [], w) else let visited = (nn) :: visited in let prepath = aux_list (neighbours g nn)... |
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 (nn,w) = node in if List.mem nn visited then raise Fail else if nn == b then (nn :: [], w) else let visited = (nn) :: visited in let prepath = aux_list (neighbours g nn... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = (notimplemented ());; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let wrong_pass_counter = ref 0 in {update_pass = (fun old_pass new_pass -> if (old_pass = !pass) then pass := new_pass else let _ = wrong_pass_counter := !wrong_pass_counter + 1 in raise wrong_pass ); show_bal... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun list edge -> let v1,v2,w = edge in if (vertex = v1) then list @ [(v2,w)] else list ) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (n,nweight) = node in if (List.mem n visited) then raise Fail else if (n = b) then visited @ [n], nweight else let nodes_neighbours = neighbours g n in if (List.length 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,nweight) = node in if (List.mem n visited) then raise Fail else if (n = b) then (fc (visited @ [n]), sc nweight) else let nodes_neighbours = neighbours g n in i... |
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 (List.length paths = 0) then None else let longest = ref (List.hd paths) in let _ = List.iter (fun path -> let _, pweight = path in let _, lweight = !longest in if (pweight >= lweight) then let _ = l... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let wrong_count = ref 0 in let deposit = ref 0 in let check_pass = (fun pass -> if !wrong_count >= 5 then (raise too_many_failures) else if pass <> !password then (wrong_count := !wrong_count + 1; raise wrong_pass) else (wrong_c... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec search_list (lst: ('a * 'a * weight) list) (acc: ('a * weight) list): ('a * weight) list = match lst with | [] -> acc | x::xs -> let (a,b,c) = x in if a = vertex then let y = (b,c) in search_list xs (y::acc) else search_list xs acc in search_list ... |
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 (vertex, w) = node in if vertex = b then (vertex::[], w) else try (List.find (fun x -> x = vertex) visited; raise Fail) with Not_found -> let lst, tot_weight = (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) fc sc : ('a list * weight)= let (vertex, w) = node in if vertex = b then sc (vertex::[], w) else try (List.find (fun x -> x = vertex) visited; fc ()) with Not_found -> aux_list (neighbours g vert... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest l max_path max_cost = match l with | [] -> if max_path != [] then Some (max_path, max_cost) else None | x::xs -> let (path, cost) = x in if cost >= max_cost then longest xs path cost else longest xs max_path max_cost in (l... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let num_of_failures = ref 0 in { update_pass = (fun oldPass newPass -> if oldPass = !password then ( password := newPass; num_of_failures := 0; ) else ( num_of_failures := !num_of_failures + 1; raise wrong... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc edge -> let (f,t,c) = edge in if (f = vertex) then acc @ [(t,c)] 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 List.mem n visited then raise Fail else if n = b then ([n],w) else let neighbours_n = neighbours g n in let (path, weight) = aux_list neighbours_n (vi... |
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 List.mem n visited then fc () else if n = b then sc ([n],w) else let neighbours_n = neighbours g n in aux_list neighbours_n (visited @ [n]) (fun... |
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 List.length paths = 0 then None else let max_weight = List.fold_left (fun acc (_, weight) -> if weight > acc then weight else acc ) min_int paths in let best_paths = List.filter (fun (_, weight) -> w... |
let open_account (initial_pass: passwd) : bank_account = let (pass, balance, fail_count) = (ref initial_pass, ref 0, ref 0) in {update_pass = (fun old_pass new_pass -> if old_pass <> !pass then (fail_count := !fail_count + 1; raise wrong_pass) else (pass := new_pass; fail_count := 0) ); retrieve = (fun input_pass amoun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc edge -> let (v1, v2, w) = edge in if v1 = vertex then (v2, w) :: acc else acc ) [] g.edges let rec print_list l = match l with | [] -> print_string "" | (e, _) :: t -> print_string e; print_string " "; print_list t let rec print_li... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (results: 'a list * weight) : ('a list * weight) = let (n, w) = node in let (rl, rw) = results in if n = b then (rl @ [n], rw + w) else aux_list (neighbours g n) (n :: visited) (rl @ [n], rw + w) ... |
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 ([b], w) else aux_list (neighbours g n) (n :: visited) fc (fun (rl, rw) -> sc (n :: rl, w + rw)) and aux_list (nodes: ('a * weigh... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec aux (paths: ('a list * weight) list) (best: ('a list * weight) option) : ('a list * weight) option = match paths with | [] -> best | (p, w) :: t -> match best with | None -> aux t (Some (p, w)) | Some (bp, bw) -> if w >= bw then a... |
let open_account (initial_pass: passwd) : bank_account = let pass= ref initial_pass in let balance= ref 0 in let wrongcount= ref 0 in let resetcount()= wrongcount:=0 in let resetpass(inputpass:passwd)= pass:= inputpass ; wrongcount:= 0 in let negativeinput(amount:int)=if amount<0 then raise negative_amount in let wrong... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let pred((a,b,c):'a*'a*weight)= a=vertex in let y=List.filter pred g.edges in let f((a,b,c):'a*'a*weight)=(b,c) in List.map f y;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (i,j)=node in if List.mem i visited then raise Fail else if i=b then ([i],j) else (let visited=visited@[i] in let (path,total)=aux_list (neighbours g i) (visited) in ([i... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (w,v)=node in if w=b then let (c,d)=sc() in (c@[w],d+v) else if List.mem w visited then fc() else aux_list(neighbours g w)(visited@[w])(fc)(fun()-> let (x,y)=sc() ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths=find_all_paths(g)(a)(b) in if paths=[] then None else let (t,u)=List.nth paths 0 in let rec pred(paths:('a list * weight) list)(biggest:int)(list_with_biggest:('a list *weight))= match paths with |[]-> list_with_biggest |(a,b)::... |
let open_account (initial_pass: passwd) : bank_account = let pass= ref initial_pass in let balance= ref 0 in let wrongcount= ref 0 in let resetcount()= wrongcount:=0 in let resetpass(inputpass:passwd)= pass:= inputpass ; wrongcount:= 0 in let negativeinput(amount:int)=if amount<0 then raise negative_amount in let wrong... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let pred((a,b,c):'a*'a*weight)= a=vertex in let y=List.filter pred g.edges in let f((a,b,c):'a*'a*weight)=(b,c) in List.map f y;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (i,j)=node in if List.mem i visited then raise Fail else if i=b then ([i],j) else (let visited=visited@[i] in let (path,total)=aux_list (neighbours g i) (visited) in ([i... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.