text stringlengths 0 601k |
|---|
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc : weight): ('a list * weight) = let (v, w) = node in if (List.mem v visited) then raise Fail else if (v = b) then (visited @ [v], acc + w) else aux_list (neighbours g v ) (visited @ [v]) (acc... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc : weight) fc sc : ('a list * weight)= let (v , w) = node in if (List.mem v visited ) then fc () else if (v = b) then sc (visited @ [v], acc+w) else aux_list (neighbours g v) (visited@[v]) (a... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f (longest) (l,w) = match longest with | None -> Some(l,w) | Some(longestPath, maxWeight) -> if (w >= maxWeight) then Some(l,w) else Some(longestPath, maxWeight) in List.fold_left f None (find_all_paths g a b) ;; |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 and password = ref initial_pass and attempts = ref 0 in let check_passwd (pass: passwd): bool = if (!attempts <= 5) then if (pass = !password) then (attempts := 0; true) else (attempts := !attempts+1; raise wrong_pass) else raise too_many_fail... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun neighbors edge -> let (v1,v2,w) = edge in if v1 = 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) (acc : weight): ('a list * weight) = let (v, w) = node in if (List.mem v visited) then raise Fail else if (v = b) then (visited @ [v], acc + w) else aux_list (neighbours g v ) (visited @ [v]) (acc... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (acc : weight) fc sc : ('a list * weight)= let (v , w) = node in if (List.mem v visited ) then fc () else if (v = b) then sc (visited @ [v], acc+w) else aux_list (neighbours g v) (visited@[v]) (a... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let f (longest) (l,w) = match longest with | None -> Some(l,w) | Some(longestPath, maxWeight) -> if (w >= maxWeight) then Some(l,w) else Some(longestPath, maxWeight) in List.fold_left f None (find_all_paths g a b) ;; |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let pass = ref initial_pass in let tries = ref 0 in { show_balance = (fun(input : passwd) -> if(5<=(!tries)) then raise too_many_failures else if((compare input !pass)=0) then !balance else raise wrong_pass; ); update_pass = (fun(input : pa... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rel_edge = List.filter(fun edge -> ((compare (origin edge) vertex) = 0)) g.edges in List.map(l_map) rel_edge ;; let ending (endcase : 'a list * weight) : ('a list * weight) = endcase ;; let exit (list: 'a list * weight) : ('a list * weight)= list exce... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (sofar : 'a list * weight) : ('a list * weight) = let vertex = fst node in let new_weight = snd node in let adjacent = neighbours g vertex in let sofar_list = fst sofar in let sofar_wt = snd sofar... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (sofar : 'a list * weight) : ('a list * weight) = let vertex = fst node in let new_weight = snd node in let adjacent = neighbours g vertex in let sofar_list = fst sofar in let sofar_wt = snd sofa... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec aux_node (node: 'a * weight) (visited : 'a list) (sofar : 'a list * weight) : ('a list * weight) = let vertex = fst node in let new_weight = snd node in let adjacent = neighbours g vertex in let sofar_list = fst sofar in let sofar... |
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let money = ref 0 in let fc = ref 0 in { update_pass = ( fun (op : passwd) (np : passwd) -> if (op = !pw) then (fc := 0 ; pw := np) else (fc := !fc + 1 ; raise wrong_pass) ); retrieve = ( fun (op : passwd) (amt : int) -> if ((op = !pw... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f1 l (_,e2,w) = ((e2,w)::l) in let f2 (e1,_,_) = e1=vertex in List.fold_left f1 [] (List.filter f2 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 ns = neighbours g (fst node) in let ns_name = fst (List.split ns) in if (List.mem b ns_name) then ([(fst node);b],snd (List.find (fun x -> (let (name,_) = x in name=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 ns = neighbours g (fst node) in let ns_name = fst (List.split ns) in if (List.mem b ns_name) then let sc_result = sc () in ((List.append (fst sc_result) [(fst node... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let path = find_all_paths g a b in if path=[] then None else let path_sorted = List.sort (fun a b -> ((snd b)-(snd a))) path in Some (List.hd path_sorted) ;; |
let open_account (initial_pass: passwd) : bank_account = let curpasswd= ref initial_pass in let balance= ref 0 in let failtime= ref 0 in {update_pass = (fun(old_pass: passwd) (new_pass: passwd) -> if (String.equal old_pass !curpasswd) then (curpasswd := new_pass; failtime:= 0) else (failtime:=!failtime+1; raise wrong_p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (checknb 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) = let nbs=List.filter (fun x -> not (List.exists (fun y->(fst x)=y) visited)) (neighbours g (fst node)) in if List.length nbs=0 then raise Fail else (if List.exists (fun x->(f... |
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 nbs=List.filter (fun x -> not (List.exists (fun y->(fst x)=y) visited)) (neighbours g (fst node)) in if List.length nbs=0 then fc() else (if List.exists (fun x->(f... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let choices:('a list * weight) list =find_all_paths g a b in let rec aux list acc = match list with |[]->None |[x]->if (snd x)>(snd acc) then Some x else Some acc |x::h->(if (snd x)>(snd acc) then (aux h x) else (aux h acc)) in aux choice... |
let open_account (initial_pass: passwd) : bank_account = let curpasswd= ref initial_pass in let balance= ref 0 in let failtime= ref 0 in {update_pass = (fun(old_pass: passwd) (new_pass: passwd) -> if (String.equal old_pass !curpasswd) then (curpasswd := new_pass; failtime:= 0) else (failtime:=!failtime+1; raise wrong_p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (checknb 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) = let nbs=List.filter (fun x -> not (List.exists (fun y->(fst x)=y) visited)) (neighbours g (fst node)) in if List.length nbs=0 then raise Fail else (if List.exists (fun x->(f... |
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 nbs=List.filter (fun x -> not (List.exists (fun y->(fst x)=y) visited)) (neighbours g (fst node)) in if List.length nbs=0 then (if List.length visited=0 then raise... |
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 curpasswd= ref initial_pass in let balance= ref 0 in let failtime= ref 0 in {update_pass = (fun(old_pass: passwd) (new_pass: passwd) -> if (String.equal old_pass !curpasswd) then (curpasswd := new_pass; failtime:= 0) else (failtime:=!failtime+1; raise wrong_p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (checknb 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) = let nbs=List.filter (fun x -> not (List.exists (fun y->(fst x)=y) visited)) (neighbours g (fst node)) in if List.length nbs=0 then raise Fail else (if List.exists (fun x->(f... |
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 nbs=List.filter (fun x -> not (List.exists (fun y->(fst x)=y) visited)) (neighbours g (fst node)) in if List.length nbs=0 then (if List.length visited=0 then raise... |
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 and balance = ref 0 and wrong = ref 0 in {update_pass = (fun old_pass new_pass -> if !password = old_pass then (wrong := 0; password := new_pass) else (wrong := !wrong + 1; raise wrong_pass) ); retrieve = (fun pass amount -> if !wr... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun nb_list (start,dest,weight) -> if vertex = start then (dest, weight) :: nb_list else nb_list) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((vertex, v_weight): 'a * weight) (visited : 'a list) : ('a list * weight) = if vertex = b then ((vertex::[]),v_weight) else try let (path_list, cost) = aux_list (neighbours g vertex) (vertex :: visited) in (vertex :: path_list, v_weigh... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((vertex, v_weight): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if vertex = b then sc ((vertex :: []),v_weight) else (let sc2 = (fun (path_list,cost) -> sc (vertex :: path_list,v_weight+cost)) in aux_list (neighbours ... |
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 find_max path_list (cur_path, cur_cost) : ('a list * weight) = match path_list with | (path, cost) :: tl -> if cost > cur_cost then find_max tl (path, cost) else find_max tl (cur_path, cur... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass and balance = ref 0 and wrong_num = ref 0 in { update_pass = (fun old_pass new_pass -> if !pass = old_pass then begin pass := new_pass; wrong_num := 0 end else begin wrong_num := wrong_num.contents + 1; raise wrong_pass end); retrieve ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = fun l (node_a, node_b, w) -> if node_a = vertex then (node_b, w)::l else l in List.fold_left f [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((n, w): 'a * weight) (visited : 'a list) : ('a list * weight) = if n = b then (List.rev (b::visited), w) else aux_list (List.map (fun (n, w') -> (n, w'+w)) (neighbours g n)) (n::visited) and aux_list (nodes: ('a * weight) list) (visite... |
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 (List.rev (b::visited), w) else sc (aux_list (List.map (fun (n, w') -> (n, w'+w)) (neighbours g n)) (n::visited) fc sc) and aux_list (nodes: ('a * w... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with |[] -> None |(path, w)::rest -> let rec helper (path, w) rest = match rest with | [] -> (path, w) | (path', w')::rest' -> if w' > w then helper (path', w') rest' else helper (path, w) rest' in Some (helper ... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in let check pass f = if pass = !password then (attempts := 0; f ()) else (incr attempts; raise wrong_pass) in let attempt pass f = if !attempts >= 5 then raise too_many_failures else ... |
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 (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if fst node = b then ([b], snd node) else if List.mem (fst node) visited then raise Fail else ((fst node) :: (fst (aux_list (neighbours g (fst node)) ((fst node) :: visited)... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if fst node = b then sc ([b], snd node) else if List.mem (fst node) visited then fc () else aux_list (neighbours g (fst node)) ((fst node) :: visited) fc (fun (p,c) ->... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec longest = function |[] -> None |[(c, d)] -> Some (c, d) |(e, f) :: (g, h) :: tl -> if f > h then longest ((e, f) :: tl) else longest ((g, h) :: tl) in longest (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass; in let fail_count = ref 0; in let show_balance = ref 0; in { update_pass = (fun old_password -> fun new_password -> if old_password <> !password then (fail_count := !fail_count + 1; raise wrong_pass ) else ((password := new_passwo... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let fold (pair: 'a * 'a * weight) ls = match pair with | (x, y, z) when x = vertex -> (y, z) :: ls | _ -> ls in List.fold_right fold 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 cur_node, w = node in if cur_node = b then (b :: [], w) else if List.mem cur_node visited then raise Fail else let path, total_weight = aux_list (neighbours g cur_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 : ('a list * weight)= let cur_node, w = node in if cur_node = b then sc (b :: [], w) else if List.mem cur_node visited then fc () else aux_list (neighbours g cur_node) (cur_node :: visited)... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(x, y)] -> Some (x, y) | (x, y) :: (a, b) :: lst -> if y >= b then max ((x, y) :: lst) else max ((a, b) :: lst) in max (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let hidden_password = ref initial_pass in let balance = ref 0 in let counter = ref 0 in let authenticator (curr_pass) : unit = if (curr_pass = !hidden_password) && (!counter < 5) then (counter := 0) else if (!counter < 5) then (counter := !counter + 1; raise wron... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun x xs -> match x with |(u, v, w) when (u = vertex) -> (v, w) :: xs |_ -> xs ) 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: weight) : ('a list * weight) = let (name, weight) = node in if name = b then (List.rev (name :: visited), (weight + total_w)) else if List.exists ((=) name) visited then raise Fail else ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) fc sc: ('a list * weight)= let (name, weight) = node in if name = b then sc (List.rev (name :: visited)) (weight) else if List.exists ((=) name) visited then fc () else let sc2 = (fun x y -> sc x... |
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_right (fun el acc -> let (_,el_weight) = el in let (_, acc_weight) = acc in if el_weight > acc_weight then el else acc) xs x) ;; |
let open_account (initial_pass: passwd) : bank_account = let curr_pass_ref = ref initial_pass in let count = ref 0 in let balance = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass <> !curr_pass_ref then (count := !count + 1; raise wrong_pass) else (count := 0; curr_pass_ref := new_pass)); deposit = (fun ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun neighbors edge -> (let (v1, v2, w) = edge in if v1 = vertex then (v2, w) :: neighbors else neighbors)) [] g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([b], 0) else let rec aux_node node visited total : ('a list * weight) = match neighbours g node with | [] -> raise Fail | _ -> aux_list (neighbours g node) visited total and aux_list nodes visited total : ('a list * weight) = match nodes ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([b], 0) else let rec aux_node node visited total fc sc : ('a list * weight) = match neighbours g node with | [] -> fc () | _ -> aux_list (neighbours g node) visited total fc sc and aux_list nodes visited total fc sc : ('a list * weight) ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | hd::tl -> (let find_max max curr = let (_, curr_wt), (_, max_wt) = curr, max in if curr_wt > max_wt then curr else max in Some (List.fold_left find_max hd tl));; |
let makeCounter () = let localCount = ref 0 in { increase = (fun () -> incr localCount; !localCount) ; reset = (fun () -> localCount := 0) } type account = { mutable password : passwd; mutable balance : int; mutable failed_attempts : int; mutable accountNotLocked : bool };; |
let open_account (initial_pass: passwd) : bank_account = let account = {password = initial_pass; balance = 0; failed_attempts = 0; accountNotLocked = true} in let pass_check pass = if account.failed_attempts >= 5 then raise too_many_failures else if pass = account.password then (account.failed_attempts <- 0; true) else... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = function | (a, b, w) -> a = vertex in let new_list = List.filter f g.edges in List.map (fun (a, b, w) -> (b, w)) new_list ;; let rec reaches_dest neighbour_nodes_weights dest = match neighbour_nodes_weights with | [] -> [] | (node, w)::xs -> if no... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([a; b], 0) else let visited_nodes = a::[] in let rec aux edges visited acc = if reaches_dest edges b != [] then ( let x = List.nth (reaches_dest edges b) 0 in let (l,w) = x in (List.rev (l::visited), w + acc) ) else match edges with | [] ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = if a = b then ([a; b], 0) else let visited_nodes = a::[] in let rec aux edges visited acc = if reaches_dest edges b != [] then ( let x = List.nth (reaches_dest edges b) 0 in let (l,w) = x in (List.rev (l::visited), w + acc) ) else match edges with | []... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = Some (find_path g a b) ;; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let attmp = ref 0 in let check_pass pwd f = if pwd = !pass then (attmp := 0; f ()) else (incr attmp; raise wrong_pass) in let attempt pwd f = if !attmp >= 5 then raise too_many_failures else check_pass pwd f i... |
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 * weight) (visited : 'a list) acc: ('a list * weight) = let (u,w) = node in if List.exists (fun v -> u = v) visited then raise Fail else if u = b then (visited@[u], acc + w) else let nbs = neighbours g u in aux_list nbs (visit... |
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 (u,w) = node in if List.exists (fun v -> u = v) visited then fc () else if u = b then sc ([u], w) else let nbs = neighbours g u in aux_list nbs (u::visited) fc (fu... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max l = match l with | [] -> None | [(p,w)] -> Some (p,w) | (p1,w1)::(p2,w2)::rest -> if w1 >=w2 then max ((p1,w1)::rest) else max ((p2,w2)::rest) in max (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let attempts = ref 0 in let total = ref 0 in let pswd = ref initial_pass in { update_pass = (fun old_pass new_pass -> if (old_pass <> !pswd ) then (attempts := !attempts +1; raise wrong_pass) else (attempts := 0; pswd := new_pass)); deposit = (fun x amount -> (if... |
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 * weight) (visited : 'a list) : ('a list * weight) = let (c,w) = node in if c = b then ([b] , w) else if List.mem c visited then raise Fail else (let (path , cost) = aux_list (neighbours g c) (c :: visited) in (c :: 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 (c,w) = node in if c = b then sc ([b], w) else if List.mem c visited then fc () else aux_list (neighbours g c) (c :: visited) fc (fun (path, cost) -> sc (c :: path... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec min l = match l with | [] -> None | [(p,w)] -> Some (p,w) | (p1,w1)::(p2,w2)::rest -> if w1 >= w2 then min ((p1,w1)::rest) else min ((p2,w2)::rest) in min (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let curr_pass = ref initial_pass in let balance = ref 0 in let bad_attempts = ref 0 in { update_pass = ( fun s1 -> fun s2 -> if s1 = !curr_pass then (bad_attempts := 0; curr_pass := s2 ) else (bad_attempts := !bad_attempts + 1; raise wrong_pass) ); retrieve = (fu... |
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 (inital_pass : passwd) : bank_account = let cur_pass = ref inital_pass in let balance = ref 0 in let num_of_tries = ref 0 in { update_pass = (fun password new_pass -> if !cur_pass = password then begin num_of_tries := 0 ; cur_pass := new_pass end else begin num_of_tries := !num_of_tries + 1; raise wron... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper acc x = let (in_vertex, out_vertex, weight) = x in if in_vertex = vertex then acc @ [(out_vertex, weight)] else acc 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) (cost: weight) (visited : 'a list) : ('a list * weight) = if node = b then (visited, cost) else aux_list (neighbours g node) cost visited and aux_list (nodes: ('a * weight) list) (cost: weight) (visited: 'a list) : ('a list *... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (cost: 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 = let helper longest x = let (_, l_cost) = longest in let (_, x_cost) = x in if x_cost > l_cost then x else longest in match find_all_paths g a b with |[] -> None |paths -> Some (List.fold_left helper ([], -1) paths) ;; |
let open_account (initial_pass: passwd) : bank_account = let truepass= ref initial_pass in let amount = ref 0 in let failures= ref 0 in { update_pass=(fun old_password new_password -> if old_password = (!truepass) then (truepass:=new_password; failures:=0) else (incr failures ;raise wrong_pass )); retrieve=(fun old_pas... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun (x : ('a * weight) list) (edge: 'a * 'a * weight) -> match edge with |(a,b,c) when a =vertex ->(b,c)::x |_ -> 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) (path:'a list * weight) : ('a list * weight) = match node with |(c,d) when c=b-> let(x,y) = path in (x@[c],(d+y)) |(c,d) when List.mem c visited -> raise Fail |(c,d)-> aux_list (neighbours g c) (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)= match node with |(c,d) when c=b-> sc node |(c,d) when List.mem c visited -> fc() |(c,d)-> aux_list (neighbours g c) (visited @[c]) fc (fun(x,y)-> let(p,q)=(sc node) in... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths= find_all_paths g a b in match paths with |[]->None |_-> Some (List.fold_left (fun(c:'a list * weight) (d:'a list * weight)-> let ((list1,weight1),(list2,weight2)) = (c, d) in if weight1 > weight2 then (list1, weight1) else (lis... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let pw = ref initial_pass in let error = ref 0 in { update_pass = ( fun old_pw new_pw -> if old_pw = !pw then (error := 0; pw := new_pw) else (error := (!error + 1) ; raise wrong_pass) ) ; retrieve = ( fun in_pw amount -> if !error = 5 then... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun x xs-> let (v1, v2, w) = x in if v1 = vertex then (v2, w)::xs else xs ) 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) (weight: int) : ('a list * weight) = let (v,w) = node in if v = b then (List.fold_left (fun xs x -> x::xs) [] (v::visited), weight + w) else if (neighbours g v) = [] then raise Fail else if List.m... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (weight: int) fc sc : ('a list * weight)= let (v,w) = node in if v = b then sc (v, w) visited weight else if (neighbours g v) = [] then fc () else if List.mem v visited then fc () else aux_list (... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let list = find_all_paths g a b in if list = [] then None else Some (List.fold_left ( fun x y -> let (l1, w1) = x in let (l2, w2) = y in if w1 > w2 then x else y ) ([a], 0) list) ;; |
let extract_pass (x1, x2, x3) = x1 let extract_balance (x1, x2, x3) = x2 let extract_times (x1, x2, x3) = x3;; |
let open_account (initial_pass: passwd) : bank_account = let account = ref (initial_pass, 0, 0) in { update_pass = (fun p1 p2 -> let old_pass = (extract_pass !account) in let balance = (extract_balance !account) in let old_times = (extract_times !account) in let _ = print_endline (old_pass ^ " " ^ p1 ^ " " ^ p2) in if ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.