text stringlengths 0 601k |
|---|
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 failed_count = ref 0 in let password = ref initial_pass in let money = ref 0 in let check_pass = fun pass -> ( if pass = !password then failed_count := 0 else (failed_count := !failed_count + 1; raise wrong_pass) ) in let check_pass_attempts = fun pass -> ( i... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left ( fun node_weights (v1,v2,w) -> if v1 = vertex then (v2,w)::node_weights else node_weights ) [] g.edges ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let append_tl list elem = List.rev (elem::(List.rev list)) in let rec aux_node (node: 'a * weight) (visited : 'a list) (acc: int) : ('a list * weight) = let (v,w) = node in if v = b then (append_tl visited b, w+acc) else if List.mem v visited then raise... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let append_tl list elem = List.rev (elem::(List.rev list)) in let rec aux_node (node: 'a * weight) (visited : 'a list) (acc: int) fc sc : ('a list * weight) = let (v,w) = node in if v = b then (append_tl visited b, w+acc) else if List.mem v visited the... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in let rec helper node rest = let (_,w) = node in match rest with | [] -> Some(node) | (v',w')::rs -> if (w' > w) then helper (v',w') rs else helper node rs in match paths with | [] -> None | x::xs -> help... |
let open_account (initial_pass: passwd) : bank_account = let user_pass = ref initial_pass in let fail_counter = ref 0 in let user_balance = ref 0 in { update_pass = (fun pass1 pass2 -> if pass1 = !user_pass then user_pass := pass2 else (fail_counter := !fail_counter + 1; raise wrong_pass) ) ; deposit = (fun pass amt ->... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let calc acc edge = let (v1, v2, w) = edge in if vertex = v1 then (v2, w):: acc else acc in let {nodes; edges} = g in List.fold_left calc [] 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 p = ref initial_pass in let f = ref 0 in let balance = ref 0 in let five = ref 5 in { update_pass = (fun old_pass new_pass -> if old_pass <> !p then (f := !f + 1; raise wrong_pass) else (p := new_pass; f := 0)) ; retrieve = (fun pass amt -> if !f = !five then... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f y acc = match y with |(v1, v2, w) -> if vertex <> v1 then acc else (v2, w)::acc in List.fold_right f g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (visited : 'a list) (node: 'a * weight) (acc: weight): ('a list * weight) = let (v,w) = node in if (v = b) then (visited@[v], acc+w) else if (List.mem v visited) then raise Fail else if 1=0 then raise Fail else aux_list (visited@[v]) (n... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (visited : 'a list) (node: 'a * weight) (acc: weight) fc sc : ('a list * weight)= let (v,w) = node in if (v = b) then sc (visited@[v], acc+w) else if (List.mem v visited) then fc () else if 1=0 then raise Fail else aux_list (visited@[v... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let funct (longest) (l,w) = match longest with | None -> Some(l,w) | Some(maxPath, maxWeight) -> if (w <= maxWeight) then Some(maxPath, maxWeight) else Some(l,w) in List.fold_left funct None (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let correct_pass = ref initial_pass in let balance = ref 0 in let pass_5 = ref 0 in { update_pass = ( fun (old_pass: passwd) (new_pass: passwd) -> if (old_pass = !correct_pass) then (correct_pass := new_pass; pass_5 := 0;) else (incr pass_5; raise wrong_pass;)); ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun list node -> let (a, b, c) = node in if a = vertex then (b, c) :: list 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) (weight1: int) (wanted: 'a) : ('a list * weight) = let (node1, weight2) = node in if List.mem node1 visited then raise Fail else if node1 == wanted then (visited@[node1], weight1 + weight2) else t... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight0: int) (wanted: 'a) fc sc : ('a list * weight)= let (node1, weight2) = node in if List.mem node1 visited then fc () else if node1 == wanted then sc (visited@[node1], weight0 + weight2) el... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented ();; |
let open_account (initial_pass: passwd) : bank_account = let pwd = ref initial_pass and balance = ref 0 and failed_attempts = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !pwd then (failed_attempts := 0; pwd := new_pass) else (failed_attempts := !failed_attempts + 1; raise wrong_pass) ); retrieve = ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let get_depart (depart, _, _) = depart in let get city edge = get_depart edge = city in let only_depart = List.filter (get vertex) (g.edges) in List.map (fun edge -> let (_, arrival, weight) = edge in (arrival, weight)) only_depart ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let acc = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list): ('a list * weight) = let (v1, w) = node in if List.mem v1 visited then (acc := !acc + w; raise Fail) else if v1 == b then (visited@[v1], !acc + w) else (acc := !acc + w; aux_li... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let acc = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= let (v1, w) = node in if List.mem v1 visited then (acc := !acc + w; fc ()) else if v1 = b then sc ((visited@[v1]), !acc+w) else (acc := !acc + w; au... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = notimplemented();; |
let open_account (initial_pass: passwd) : bank_account = let account_pass = ref initial_pass in let wrong_count = ref 0 in let balance = ref 0 in let check_pass pass = if pass <> !account_pass then (wrong_count := !wrong_count + 1; raise wrong_pass) else wrong_count := 0 in let check_lock () = if !wrong_count >= 5 then... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun neighbours (a, b, w) -> if a = vertex then (b, w) :: neighbours else 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) : ('a list * weight) = let (v, w) = node in if v = b then ([v], w) else if List.exists (fun n -> n = v) visited then raise Fail else let nodes = neighbours g v in let (path, weight) = aux_list 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 ([v], w) else if List.exists (fun n -> n = v) visited then fc () else let nodes = neighbours g v in aux_list nodes (v :: 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 if all_paths = [] then None else Some (List.fold_left (fun (max_path, max_weight) (path, weight) -> if weight > max_weight then (path, weight) else (max_path, max_weight)) ([], 0) all_paths);; |
let open_account (initial_pass: passwd) : bank_account = let pass= ref initial_pass in let balance= ref 0 in let counter= ref 0 in let u= (fun o n -> if o= !pass then (pass:= n ;counter:= 0) else (counter:= !counter+1 ;raise wrong_pass)) in let r= (fun p ammt ->if !counter > 4 then raise too_many_failures else if p = !... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f= (fun ini (x,y,w) -> if x=vertex then List.append ini [(y,w)] else ini) in List.fold_left f [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = 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 pass= ref initial_pass in let balance= ref 0 in let counter= ref 0 in let u= (fun o n -> if o= !pass then (pass:= n ;counter:= 0) else (counter:= !counter+1 ;raise wrong_pass)) in let r= (fun p ammt ->if !counter > 4 then raise too_many_failures else if p = !... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f= (fun ini (x,y,w) -> if x=vertex then List.append ini [(y,w)] else ini) in List.fold_left f [] g.edges let rec find b l= match l with |[]-> (b,-1) |x::xs-> let (u,v)=x in if b=u then x else (find b xs);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let acc= ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (u,v)=node in match (find b (neighbours g u)) with |(b,-1)-> (acc:= !acc+v; aux_list (neighbours g u) (visited@[u])) |(c,d)-> (visited @ [u] @ [c] , !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)= 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 pass= ref initial_pass in let balance= ref 0 in let counter= ref 0 in let u= (fun o n -> if o= !pass then (pass:= n ;counter:= 0) else (counter:= !counter+1 ;raise wrong_pass)) in let r= (fun p ammt ->if !counter > 4 then raise too_many_failures else if p = !... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f= (fun ini (x,y,w) -> if x=vertex then List.append ini [(y,w)] else ini) in List.fold_left f [] g.edges let rec find b l= match l with |[]-> (b,-1) |x::xs-> let (u,v)=x in if b=u then x else (find b xs);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let acc= ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (u,v)=node in match (find b (neighbours g u)) with |(b,-1)-> (acc:= !acc+v; aux_list (neighbours g u) (visited@[u])) |(c,d)-> (visited @ [u] @ [c] , !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)= 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 pass= ref initial_pass in let balance= ref 0 in let counter= ref 0 in let u= (fun o n -> if o= !pass then (pass:= n ;counter:= 0) else (counter:= !counter+1 ;raise wrong_pass)) in let r= (fun p ammt ->if !counter > 4 then raise too_many_failures else if p = !... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f= (fun ini (x,y,w) -> if x=vertex then List.append ini [(y,w)] else ini) in List.fold_left f [] g.edges let rec find b l= match l with |[]-> (b,-1) |x::xs-> let (u,v)=x in if b=u then x else (find b xs);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = try let acc= ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (u,v)=node in match (find b (neighbours g u)) with |(b,-1)-> (acc:= !acc+v; aux_list (neighbours g u) (visited@[u])) |(c,d)-> (visited @ [u;c] , !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)= 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 loc_pass = ref initial_pass in let total = ref 0 in let fails = ref 0 in { update_pass = (fun (old_pass :passwd) (new_pass:passwd) -> if(old_pass= !loc_pass) then (loc_pass:=new_pass; fails:= 0;) else (fails := (!fails+1); raise wrong_pass) ); retrieve = (fun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * int) list = let (_,y) = List.fold_left folding (vertex,[]) g.edges in 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 (x,y) = node in if(x=b)then (b::visited,y) else aux_list (List.map (function (c,d)->(c,d+y)) (neighbours g x)) (x::visited) and aux_list (nodes: ('a * weight) list) (vis... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (fc : unit ->'a list * weight ) (sc : 'a -> weight -> 'a list -> 'a list*weight) : ('a list * weight)= let (x,y) = node in if(x=b) then sc x y visited else if (List.mem x visited) then fc () else... |
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 match all_paths with | [] -> None | _ -> Some (List.fold_left fold2 ([],0) all_paths);; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass and wrongPasswordCounter = ref 0 and balance = ref 0 in { update_pass = (fun (oldPassword : passwd) (newPassword : passwd) -> if oldPassword = !password then (wrongPasswordCounter := 0; password := newPassword) else (wrongPasswordC... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun acc (v1, v2, w) -> 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 (visited : 'a list) ((node, cost) : 'a * weight) : ('a list * weight) = if node = b then ([b] , cost) else if List.mem node visited then raise Fail else let (newPath, newWeight) = aux_list (node :: visited) (neighbours g node) in (node ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (visited : 'a list) ((node, cost): 'a * weight) failContinuation successContinuation : ('a list * weight) = if node = b then successContinuation ([b], cost) else if List.mem node visited then failContinuation () else aux_list (node :: ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | (currentPath, cost1) :: (nextPath, cost2) :: tl -> if cost2 < cost1 then max ((currentPath, cost1) :: tl) else max ((nextPath, cost2) :: tl) | [(path, cost)] -> Some(path, cost) in max (find_all... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let wrong_attempts = ref 0 in let reset_attempts = (fun () -> wrong_attempts := 0) in { update_pass = (fun old_pass new_pass -> if old_pass = !pass then (pass := new_pass; reset_attempts ()) else (wrong_attemp... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges vertex = match edges with | [] -> [] | l::ls -> let (v, n, w) = l in if v = vertex then (n, w)::helper ls v else helper ls vertex in helper 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) (cur_list: 'a list * weight): ('a list * weight) = if List.exists (fun x -> x = fst node) visited then raise Fail else if fst node = b then ((fst cur_list)@[fst node], (snd cur_list) + (snd node))... |
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 (cur_path : 'a list * weight) : ('a list * weight) = if List.exists (fun x -> x = fst node) visited then fc () else if fst node = b then sc ((fst cur_path)@[fst node], (snd cur_path) + (snd... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (list: ('a list * weight) list) (longest_so_far: 'a list * weight) : ('a list * weight) option = match list with | [] -> if (fst longest_so_far) = [] then None else Some longest_so_far | l::ls -> if (snd l) > (snd longest_s... |
let makeFailCounter() = let localCount = ref 0 in { increase = (fun () -> incr localCount;); reset = (fun () -> localCount := 0); count_fails = (fun () -> !localCount); };; |
let open_account (initial_pass: passwd) : bank_account = let acc_pass = ref initial_pass in let balance = ref 0 in let fails = makeFailCounter() in { update_pass = (fun old_pass new_pass -> if old_pass <> !acc_pass then (fails.increase (); raise wrong_pass;); acc_pass := new_pass; fails.reset ();); retrieve = (fun pass... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (v1,v2,w) -> (v2,w)) (List.filter (fun (v1,_,_) -> 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) (acc: int): ('a list * weight) = let (n,w) = node in if (List.exists (fun a -> a = n) visited) then raise Fail; if n = b then ((visited @ [n]),acc) else try aux_list (neighbours g n) (visited @ [n... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc : int) fc sc : ('a list * weight)= let (n,w) = node in if (List.mem n visited) then fc else( if n = b then sc (visited,n,w) else( (aux_list (neighbours g n) (visited @ [n]) acc fc sc))) and ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths = find_all_paths g a b in let rec longest_path (paths: ('a list * weight) list) (longest: 'a list * weight) : ('a list * weight) option = match paths with | [] -> if longest = ([],0) then None else Some longest | hd::tl -> if (L... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in { update_pass = (fun old_pass new_pass -> if(old_pass = !password) then (counter := 0; password := new_pass) else (counter := !counter + 1; raise wrong_pass)); retrieve = (fun old_pa... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let {nodes=n; edges=e} = g in let rec neighbours' e vertex acc = match e with |[] -> acc |h :: tl -> let (a, b, c) = h in if(a = vertex) then neighbours' tl vertex ((b, c) :: acc) else neighbours' tl vertex acc in neighbours' e vertex [];; |
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) = let (n, w) = node in if(n = b) then (List.rev (n::visited), !w' + w) else if(List.mem n visited) then raise Fail else (w' := !w' + w; aux_list (neighbours ... |
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)= let (n, w) = node in print_endline n;if(n = b) then sc (List.rev (n::visited), !w' + w) else if(List.mem n visited) then fc () else (w' := !w' + w; a... |
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 find_highest_cost l acc value = match l with | [] -> Some (acc, value) | h::tl -> let (l2, v') = h in if(v' > value) then find_highest_cost tl (l2) (v') else find_highest_cost tl acc value in if (l ... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let amount = ref 0 in let counter = ref 0 in let helper x = if x < 0 then raise negative_amount else raise not_enough_balance in { update_pass = (fun old_pass new_pass -> if (old_pass = !password) then (counter := 0; password :=... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edges = g.edges in let list = List.filter (fun (x, y, z) -> x = vertex) edges in let rec find_neighbours xs = match xs with | [] -> [] | (x, y, z)::t -> (y, z):: (find_neighbours t) in find_neighbours 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 (v, weight) = node in let list_neighbours = neighbours g v in if (List.mem v visited) then raise Fail else if v = b then ([v], weight) else let (list, total) = 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 (v, weight) = node in let list_neighbours = neighbours g v in if (List.mem v visited) then fc () else if v = b then sc ([v], weight) else aux_list list_neighbours... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest list = match list with | [] -> None | [(list, weight)] -> Some (list, weight) | (list, weight)::(list2, weight2)::xs -> if weight >= weight2 then longest ((list, weight)::xs) else longest ((list2, weight2)::xs) in longest ... |
let open_account (initial_pass: passwd) : bank_account = let ref_mdp = ref initial_pass in let ref_balance = ref 0 in let ref_nombre_derreurs = ref 0 in let mettre_a_jour_le_mdp (vieux_mdp : passwd) (nouveau_mdp : passwd) = let mdp = !ref_mdp in if String.equal mdp vieux_mdp then (ref_nombre_derreurs := 0 ; ref_mdp := ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = g.edges |> List.filter (fun edge -> let u, _, _ = edge in u = vertex) |> List.map (fun edge -> let _, v, weight = edge in (v, weight));; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let child_nodes (g : 'a graph) (node : ('a * weight)) : ('a * weight) list = g.edges |> List.filter (fun (debut, _, _) -> debut = fst node) |> List.map (fun (_, fin, edge_weight) -> (fin, edge_weight + snd node)) in let rec aux_node (node: 'a * weight) ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let child_nodes (g : 'a graph) (node : ('a * weight)) : ('a * weight) list = g.edges |> List.filter (fun (debut, _, _) -> debut = fst node) |> List.map (fun (_, fin, edge_weight) -> (fin, edge_weight + snd node)) in let rec aux_node (node: 'a * weight)... |
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 all_paths |> List.fold_left (fun (longest_so_far : ('a list * weight) option) ((next_path, next_length) : ('a list * weight)) -> match longest_so_far with | None -> Some (next_path, next_length) | S... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let failure_counter = ref 0 in { update_pass = (fun passwd1 -> fun passwd2 -> if passwd1 <> !password then (failure_counter := !failure_counter + 1 ; raise wrong_pass) else password := passwd2 ; failure_co... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l v acc = match l with | [] -> acc | hd :: tl -> let (t,d,w) = hd in if t = v then helper tl v ((d,w) :: acc) else helper tl v acc in helper g.edges vertex [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) = let rec aux_list nodes visited acc = if not(List.mem a visited) then aux_list nodes (a::visited) acc else match nodes with | [] -> raise Fail | (d,w)::tl -> if List.mem d visited then aux_list tl visited acc else ( if d = b then (List.rev (b::visited),acc+w) else let visite... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list nodes visited fc sc = if not(List.mem a visited) then aux_list nodes (a::visited) fc sc else match nodes with | [] -> fc () | (d,w)::tl -> if List.mem d visited then aux_list tl visited fc sc else ( if d = b then (List.rev (b::visited)... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let result = find_all_paths g a b in let l' = ref [] in let w' = ref 0 in match result with | [] -> None | (l,w) :: tl -> let rec helper result' = match result' with | [] -> Some (!(l'),!(w')) | (d,c) :: tl -> if c > (!w') then (l' := d ;... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let failure_counter = ref 0 in { update_pass = (fun passwd1 -> fun passwd2 -> if passwd1 <> !password then (failure_counter := !failure_counter + 1 ; raise wrong_pass) else password := passwd2 ; failure_co... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l v acc = match l with | [] -> acc | hd :: tl -> let (t,d,w) = hd in if t = v then helper tl v ((d,w) :: acc) else helper tl v acc in helper g.edges vertex [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) = let rec aux_list nodes visited acc = if not(List.mem a visited) then aux_list nodes (a::visited) acc else match nodes with | [] -> raise Fail | (d,w)::tl -> if List.mem d visited then aux_list tl visited acc else ( if d = b then (List.rev (b::visited),acc+w) else let visite... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list nodes visited fc sc = if not(List.mem a visited) then aux_list nodes (a::visited) fc sc else match nodes with | [] -> fc () | (d,w)::tl -> if List.mem d visited then aux_list tl visited fc sc else ( if d = b then (List.rev (b::visited)... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let result = find_all_paths g a b in let l' = ref [] in let w' = ref 0 in match result with | [] -> None | (_,_) :: _ -> let rec helper result' = match result' with | [] -> Some (!(l'),!(w')) | (d,c) :: tl -> if c > (!w') then (l' := d ; ... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let amount = ref 0 in let errors = ref 0 in { update_pass = (fun (i:passwd) (n:passwd) -> if i = !pass then (pass:= n; errors := 0) else (errors := !errors + 1; raise wrong_pass) ); retrieve = (fun (i:passwd) (removed:int) -> if !er... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edgeNum = edgeCounter g.edges in if edgeNum = 0 then [] else ( let rec appender (edges: (string * string * int) list) (vertex: 'a) (finalList: (string * int) list) = match edges with | [] -> finalList | x::xs -> ( if (getT1 x) = vertex then ( appender... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec helper (a: string) (b : string) (l: string list) (w: weight) (v: string list) (flag:bool): (string list * weight) = if flag then (l, w) else let theNeighbours = neighbours g a in match theNeighbours with | [] -> raise Fail | x::xs -> ( if (getT1... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.