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) : ('a list * weight) = let (name, weight) = node in let list = neighbours g name in if name = b then ([], 0) else aux_list list visited and aux_list (nodes: ('a * weight) list) (visited: 'a 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 (name, weight) = node in let list = neighbours g name in if name = b then sc ([], 0) else aux_list list visited fc sc and aux_list (nodes: ('a * weight) list) (vis... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec aux list best_path best_weight = match list with | [] -> best_path | h :: t -> let (list, weight) = h in if weight > best_weight then aux t h weight else aux t best_path best_weight in let all_paths = find_all_paths g a b in match... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let current_password = ref initial_pass in let attempt = ref 0 in let new_account : bank_account = { update_pass = (fun (old_pass : passwd) (new_pass : passwd) -> if (old_pass = !current_password) then let () = attempt := 0 in current_passw... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge_list = g.edges in let node_finder n l = match n with | (v1, v2, wt) when v1 = vertex -> (v2, wt) :: l | _ -> l in List.fold_right node_finder edge_list [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (cur_weight : weight) : ('a list * weight)= match node with | (dest, wt) when dest == b -> (visited @ [dest], cur_weight + wt) | (c, wt) when (List.mem c visited) -> raise Fail | (n, wt) -> aux_li... |
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 | (v2, wt) when v2 = b -> (visited @ [v2], sc wt) | (v2, wt) when (List.mem v2 visited) -> fc () | (v2, wt) -> let new_sc = (fun x -> (sc x) + wt) in a... |
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 | _ -> let cur_path = ref (List.nth all_paths 0) in let update_max (path : 'a list * weight) : unit = match path, !cur_path with | (p1, wt1), (p2, wt2) when wt1 >= ... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let current_password = ref initial_pass in let attempt = ref 0 in let new_account : bank_account = { update_pass = (fun (old_pass : passwd) (new_pass : passwd) -> if (old_pass = !current_password) then let () = attempt := 0 in current_passw... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge_list = g.edges in let node_finder n l = match n with | (v1, v2, wt) when v1 = vertex -> (v2, wt) :: l | _ -> l in List.fold_right node_finder edge_list [] ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (cur_weight : weight) : ('a list * weight)= match node with | (v2, wt) when v2 == b -> (visited @ [v2], cur_weight + wt) | (v2, wt) when (List.mem v2 visited) -> raise Fail | (v2, wt) -> 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)= match node with | (v2, wt) when v2 = b -> (visited @ [v2], sc wt) | (v2, wt) when (List.mem v2 visited) -> fc () | (v2, wt) -> let new_sc = (fun x -> (sc x) + wt) in a... |
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 | _ -> let cur_path = ref (List.nth all_paths 0) in let update_max (path : 'a list * weight) : unit = match path, !cur_path with | (p1, wt1), (p2, wt2) when wt1 >= ... |
let open_account (initial_pass: passwd) : bank_account = let banking = ref initial_pass in let balance = ref 0 in let count = ref 0 in { update_pass = (fun x y -> if (!banking = x) then ( count := 0; banking := y) else ( count := (!count + 1); raise wrong_pass )); retrieve = (fun x y -> if (!count = 5) then raise too_m... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (x,y,z) acc -> (y,z) :: acc) (List.filter (fun (x,y,z)-> x=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) (count): ('a list * weight) = if ((getele1 node) = b) then ((b :: visited), count + (getele2 node)) else if (List.length (g.edges) = 0 || List.length (neighbours g (getele1 node)) = 0) then raise ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (count) fc sc : ('a list * weight)= if ((getele1 node) = b) then sc ((b :: visited), count + (getele2 node)) else if (List.mem (getele1 node) (visited)) then fc () else aux_list (neighbours g (ge... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = match find_all_paths g a b with | [] -> None | _ -> Some (List.fold_right (fun x y -> if (getele2 x) >= (getele2 y) then x else y) (find_all_paths g a b) (([], 0)) );; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let fail_login = ref 0 in let balance = ref 0 in let update_pass request_password new_password = if (request_password = !password) then (fail_login := 0; password := new_password) else (fail_login := !fail_login + 1; raise wrong... |
let neighbours (g: 'a graph) (vertex: 'a) = let add_edge (init: ('a * 'b) list) (edge: 'a * 'a * weight) = let ((v1: 'a), (v2: 'a),(w: weight)) = edge in if vertex = v1 then List.append init [(v2,w)] else init in List.fold_left add_edge [] g.edges ;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let total_weight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = let (v1,w) = node in if v1 = b then (total_weight := !total_weight + w; (List.append visited [v1], !total_weight)) else if List.mem v1 visited th... |
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,w) = node in if v1 = b then sc (List.append visited [v1]) w else if List.mem v1 visited then fc () else let fc2 = fun () -> aux_list (neighbours g v1) (List.ap... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let compare l1 l2 = match l1 with | None -> let (v2, w2) = l2 in Some(v2,w2) | Some(v1,w1) -> let (v2, w2) = l2 in if w2 <= w1 then Some (v1, w1) else Some(v2, w2) in List.fold_left compare None (find_all_paths g a b);; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let count_balance = ref 0 in let passwd_tries = ref 0 in let wrong_passwd = fun input_pass -> (compare (!pass) input_pass) != 0 in { update_pass = (fun old_pass -> fun new_pass -> if wrong_passwd old_pass then let _ = (passwd_tries ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = if g.edges = [] then [] else let f1 = fun edge -> let (a,_,_) = edge in (a = vertex) in let new_lst = List.filter f1 g.edges in if new_lst = [] then [] else let f2 = fun edge -> let (_,b,weight) = edge in (b,weight) in List.map f2 new_lst ;; |
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 (city,weight) = node in if city = b then ([b], weight) else if let compare visit = (compare visit city = 0) in (List.exists compare visited) then raise Fail else let (re... |
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 (city,weight) = node in if city = b then sc ([b], weight) else if let compare visit = (compare visit city = 0) in (List.exists compare visited) then fc () else le... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max ( lst : ('a list * weight) list) = match lst with | [] -> None | [(path,weight)] -> Some (path,weight) | (path1,weight1) :: (path2,weight2) :: rest_paths -> if weight1 > weight2 then max ( (path1,weight1)::rest_paths ) else if... |
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 cur_pass new_pass -> if (cur_pass = !password) then (counter := 0; password := new_pass) else (counter := !counter + 1; raise wrong_pass)); retrieve = (fun pas... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec removeFirst l1 l2= match l1 with |[] -> l2 |x::xs -> let (n1,n2,w) = x in if (n1 = vertex) then removeFirst xs l2@[(n2,w)] else removeFirst xs l2 in removeFirst g.edges [];; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let path = ref [] in let totalWeight = ref 0 in let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = if ((fst node) = b) then (((fst node)::(!path)),(snd node) + (!totalWeight)) else if (List.mem (fst node) visited) then (rais... |
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 (visited@[(fst node)]) (snd node)) else if (List.mem (fst node) visited) then fc () else let fc2 = fun() -> (aux_list (neighbours g (fst n... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let compare_path path1 path2 = if ((snd path1) > (snd path2)) then 1 else if ((snd path1) < (snd path2)) then (-1) else 0 in if ((find_all_paths g a b) = []) then None else let l1 = List.sort compare_path (find_all_paths g a b) in let l2 ... |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let incorrect_count = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !pass then (incorrect_count := 0 ; pass := new_pass) else (incr incorrect_count; raise wrong_pass)); deposit = (fun old_pa... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper l = match l with | [] -> [] | (from, toc, weight)::tl -> if from = vertex then (toc, weight) :: helper tl else helper tl in helper g.edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec process_node (node: 'a * weight) (visited : 'a list) (acc : int) : ('a list * weight) = if fst(node) = b then ((List.rev (fst(node)::visited)), acc + snd(node)) else if List.exists (fun y -> fst(node) = y) visited then raise Fail else (process_l... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec process_node (node: 'a * weight) (visited : 'a list) (acc : int) fc sc : ('a list * weight)= if fst(node) = b then ((List.rev (b::visited)), acc + snd(node)) else if List.exists (fun y -> fst(node) = y) visited then fc () else (process_list (ne... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max list cur_max = match list with | [] -> cur_max | x :: xs -> if(snd(x)>snd(cur_max)) then max xs x else max xs cur_max in if List.length (find_all_paths g a b) = 0 then None else Some (max (List.tl (find_all_paths g a b)) (List... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let error_count = ref 0 in { update_pass = (function oldpasswd -> function newpasswd -> if oldpasswd = !password then (error_count := 0; password := newpasswd) else (error_count := !error_count + 1; raise ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = get_neighbours g.edges vertex [] ;; neighbours g "p1";; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) rl rw : ('a list * weight) = match (List.mem (fst(node)) visited) with | true -> raise Fail | false -> if fst(node) = b then (rl @ [(fst(node))], rw+(snd(node))) else aux_list (neighbours g (fst(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 rl rw : ('a list * weight)= match (List.mem (fst(node)) visited) with | true -> fc () | false -> if fst(node) = b then sc (rl @ [(fst(node))], rw+(snd(node))) else aux_list (neighbours g (f... |
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 max = ref ([],0) in let f c = if (snd(c)) > (snd(!max)) then max := c else max := !max in match l with | [] -> None | _ -> let _ = (List.iter f l) in Some !max ;; |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let passw = ref initial_pass in let attempts = ref 0 in {update_pass = (fun input_pass new_pass -> if input_pass = !passw then (attempts := 0 ;passw := new_pass) else (attempts := !attempts + 1; raise wrong_pass)); retrieve = (fun pass num ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper e v f= match e with | [] -> f [] | (v1,v2,w)::xs -> if v1 = v then helper xs v (fun u -> f ((v2,w)::u)) else helper xs v f in let lst = g.edges in helper lst vertex (fun u -> u);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (visited : 'a list) (num : weight) : ('a list * weight) = if node = b then (List.rev visited,num) else aux_list (neighbours g node) visited num and aux_list (nodes: ('a * weight) list) (visited: 'a list) (num : weight) : ('a ... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a) (visited : 'a list) fc sc : ('a list * weight)= if node = b then (fc [], sc 0) else aux_list (neighbours g node) visited fc sc and aux_list (nodes: ('a * weight) list) (visited: 'a list) fc sc : ('a list * weight) = match no... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec max (paths: ('a list * weight) list) (max_path: ('a list * weight)) (max_cost: int) : ('a list * weight) option = match paths with |[] -> Some max_path |(node,w)::xs -> if w > max_cost then max xs (node,w) w else max xs max_path m... |
let open_account (initial_pass: passwd) : bank_account = let balance = ref 0 in let counter = ref 0 in let current_pass = ref initial_pass in { update_pass = (fun a b -> if (a = !current_pass) then (current_pass := b; counter := 0) else (counter := !counter + 1; raise wrong_pass)); retrieve = (fun a b -> if (!counter >... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.map (fun (v, w, n) -> (w, n)) (List.filter (fun (v, w, n) -> v = 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) = match node with | (v, w) when v = b -> ([b], w) | (v, _) when List.mem v visited -> raise Fail | (v, w) -> let c = aux_list (neighbours g v) (v::visited) in (v::(fst c), 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)= match node with | (v, w) when v = b -> sc([b], w) | (v, _) when List.mem v visited -> fc () | (v, w) -> aux_list (neighbours g v) (v::visited) fc (fun (s, t) -> sc(v::... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let l = find_all_paths g a b in match List.length l with | 0 -> None | 1 -> Some (List.hd l) | _ -> Some (List.nth (List.sort (fun c d -> compare (snd c) (snd d)) l) (List.length l - 1));; |
let open_account (initial_pass: passwd) : bank_account = let myPass = ref initial_pass in let myMoney = ref 0 in let failuresCounter = ref 0 in { update_pass = (fun givenPass newPass -> if givenPass = !myPass then (failuresCounter := 0; myPass := newPass) else (failuresCounter := !failuresCounter +1; raise wrong_pass) ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let fy (lst:('a*weight) list) (tup:'a*'a*weight) : ('a*weight) list= let (me,neb,wei)= tup in if me = vertex then (neb,wei) :: lst else lst in List.fold_left fy [] 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 ( [(fst node)], (snd node)+0) else if (List.mem (fst node) visited) then raise Fail else let (myPath,myWei) = aux_list (neighbours g (fst node) ) ( (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)= if (fst node) = b then sc ( [(fst node)], (snd node)) else if (List.mem (fst node) visited) then fc() else let sc3 y= sc ((fst node)::(fst y), (snd node)+(snd y)) in a... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let allPaths = find_all_paths g a b in let compWeights p1 p2 = if (snd p1) = (snd p2) then 0 else if (snd p1) > (snd p2) then 1 else (-1) in let sortedPaths = List.sort compWeights allPaths in if List.length sortedPaths = 0 then None else... |
let open_account (initial_pass: passwd) : bank_account = let passref = ref(initial_pass) in let balance = ref(0) in let failures = ref(0) in let retrieve = (fun pass withdrawl -> if(!failures>=5) then raise (too_many_failures) else( if (pass = !passref) then (failures:=0; if(withdrawl<0) then raise negative_amount else... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neighbourshelper edges vertex acc= match edges with |[]->acc [] |(fromnode,tonode,weight)::xs ->if(fromnode=vertex) then neighbourshelper xs vertex (fun list->acc((tonode,weight)::list)) else neighbourshelper xs vertex acc in let {nodes;edges}=g i... |
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 (place,distance) = node in if(place = b) then ([b],distance) else (let y = (aux_list (neighbours g place) (visited)) in (place::fst y, (distance+snd y))) and aux_list (no... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node node visited fc sc = let (place,distance) = node in if(place = b) then sc ([b],distance) else (aux_list (neighbours g place) (visited) fc (fun tuple -> sc(place::fst tuple, distance+snd tuple))) and aux_list (nodes: ('a * weight) list)... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let comparepaths = fun tuple1 tuple2 ->((snd tuple2)-(snd tuple1)) in match (List.sort comparepaths (find_all_paths g a b)) with |[] ->None |x::xs -> Some(x);; |
let open_account (initial_pass: passwd) : bank_account = let curPasswd= ref initial_pass in let curBalance= ref 0 in let numofWrongPasswd= ref 0 in { update_pass= (fun oldPasswd -> fun newPasswd -> if oldPasswd= !curPasswd then (curPasswd:= newPasswd; numofWrongPasswd:= 0) else (numofWrongPasswd:= !numofWrongPasswd+ 1;... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let result= (List.exists (fun x-> x= vertex) g.nodes) in if (not(result)) then (raise wrong_pass) else ( List.fold_left (fun a-> fun (v1, v2, w)-> if (v1= vertex) then ((v2, w):: a) else a) [] g.edges );; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (nodes: ('a * weight) list) ((visitedNodes, weights): ('a list * weight)) : ('a list * weight) = match nodes with |[]-> raise Fail |(v, w) :: xs -> if (not(List.exists (fun x-> x= v) visitedNodes)) then( if v= b then (visitedNodes @ [v]... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (nodes: ('a * weight) list) ((visitedNodes, weights): ('a list * weight)) fc sc : ('a list * weight) = let check (y, _)= not(List.exists (fun x-> x= y) visitedNodes) in match List.filter check nodes with |[]-> fc () |(v, w) :: xs -> if... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper paths (visitedNodes, weights)= match paths with |[] -> Some (visitedNodes, weights) |(v, w):: xs-> if (w> weights) then helper xs (v, w) else helper xs (visitedNodes, weights) in match (find_all_paths g a b) with |[]-> None... |
let open_account (initial_pass: passwd) : bank_account = let curPasswd= ref initial_pass in let curBalance= ref 0 in let numofWrongPasswd= ref 0 in { update_pass= (fun oldPasswd -> fun newPasswd -> if oldPasswd= !curPasswd then (curPasswd:= newPasswd; numofWrongPasswd:= 0) else (numofWrongPasswd:= !numofWrongPasswd+ 1;... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let result= (List.exists (fun x-> x= vertex) g.nodes) in if (not(result)) then (raise Fail) else ( List.fold_left (fun a-> fun (v1, v2, w)-> if (v1= vertex) then ((v2, w):: a) else a) [] g.edges );; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (nodes: ('a * weight) list) ((visitedNodes, weights): ('a list * weight)) : ('a list * weight) = match nodes with |[]-> raise Fail |(v, w) :: xs -> if (not(List.exists (fun x-> x= v) visitedNodes)) then( if v= b then (visitedNodes @ [v]... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_list (nodes: ('a * weight) list) ((visitedNodes, weights): ('a list * weight)) fc sc : ('a list * weight) = let check (y, _)= not(List.exists (fun x-> x= y) visitedNodes) in match List.filter check nodes with |[]-> fc () |(v, w) :: xs -> if... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper paths (visitedNodes, weights)= match paths with |[] -> Some (visitedNodes, weights) |(v, w):: xs-> if (w> weights) then helper xs (v, w) else helper xs (visitedNodes, weights) in match (find_all_paths g a b) with |[]-> None... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let incorrectTries = ref 0 in let retrieve inPass money = if !incorrectTries >= 5 then raise too_many_failures else if money < 0 then raise negative_amount else if !password = inPass then if !balance > mon... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec neigh_rec edgest vert = match edgest with | [] -> [] | (v,w,weight)::xs -> if v = vert then (w,weight)::(neigh_rec xs vert) else (neigh_rec xs vert) in neigh_rec g.edges vertex;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) : ('a list * weight) = 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 balance = ref 0 in let password = ref initial_pass in let num_fails = ref 0 in { update_pass = (fun old_pass new_pass -> if old_pass = !password then (num_fails := 0; password := new_pass) else (num_fails := !num_fails+1; raise wrong_pass)); retrieve = (fun p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let f = fun acclist edge -> let (v1, v2, w) = edge in if v1 = vertex then ((v2, w) :: acclist) else acclist 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) (accweight: weight) : ('a list * weight) = let (value, weight) = node in let neighbourlist = neighbours g value in if (value = b) then (visited @ [b], (accweight + weight)) else aux_list neighbour... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node (node: 'a * weight) (visited : 'a list) (accweight: weight) fc sc : ('a list * weight) = let (value, weight) = node in let neighbourlist = neighbours g value in if (value = b) then sc (visited @ [b], (accweight + weight)) else aux_list... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let paths_list = find_all_paths g a b in if (paths_list = []) then None else let rec find_max_path_weight l = match l with | [] -> -1 | (path, path_weight) :: [] -> path_weight | (path, path_weight) :: ls -> max path_weight (find_max_path... |
let open_account (initial_pass: passwd) : bank_account = let passw = ref initial_pass in let a : int ref = ref 0 in let b : int ref = ref 0 in { update_pass = (fun oldp newp -> if oldp = !passw then b:= (!b - !b) else b:= (!b + 1) ; if !b = 0 then passw := newp else raise wrong_pass ); deposit = (fun passtest depos -> ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let fun1 l edge = let (node1,node2,weight) = edge in if node1 = vertex then (List.append l [(node2,weight)]) else l in let {nodes = nodelist; edges = edgelist } = g in List.fold_left fun1 [] edgelist;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let neighbours2 (g: 'a graph) (vertex: 'a) = let hmmm w edge = let (node1,node2,weight) = edge in if node1 = vertex then (List.append w [node2]) else w in let {nodes = nodelist; edges = edgelist } = g in List.fold_left hmmm [] edgelist in let rec aux 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)= 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 allpath = find_all_paths g a b in let rec allweights l = match l with |[] -> [] |(a,b)::[] -> [b] |(a,b)::f -> b :: (allweights f) in let rec most lista = match lista with |[] -> 0 |x::[] -> x |x::t -> let y = most t in if x > y then ... |
let open_account (initial_pass: passwd) : bank_account = let password_tries = ref 0 and actual_password = ref initial_pass and balance = ref 0 in {update_pass = (fun old_pass new_pass -> if (compare !actual_password old_pass = 0) then (actual_password := new_pass; password_tries := 0) else if (compare !actual_password ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let outgoing_edges = List.filter (fun tup -> is_neighbor vertex tup) g.edges in List.map (fun tup -> let (_,o,w) = tup in (o, w)) outgoing_edges ;; let neighbor_in_visited (neighbor: 'a) (visited: 'a list) = (List.mem neighbor visited) let get_node a = le... |
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 (compare (get_node node) b = 0) then ([b], ((get_weight node))) else if (neighbor_in_visited (get_node node) visited) then raise Fail else (let (path , cost_so_far) = aux... |
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 (compare (get_node node) b = 0) then sc ([b], ((get_weight node))) else if (neighbor_in_visited (get_node node) visited) then fc () else aux_list (neighbours g (get... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let all_paths_list = find_all_paths g a b in if (compare (List.length all_paths_list) 0 = 0) then None else max all_paths_list (List.hd all_paths_list);; |
let fail_count () : count_failures = let failures = ref 0 in {increase = (fun () -> failures := !failures + 1; !failures); reset = (fun () -> failures := 0); number = (fun () -> !failures) } ;; type account_info = { password : string ref; balance : int ref; failures : count_failures};; |
let open_account (initial_pass: passwd) : bank_account = let account = {password = ref initial_pass; balance = ref 0; failures = fail_count ()} in {update_pass = (fun old_pass new_pass -> if old_pass = !(account.password) then let fails = (account.failures).reset () in account.password := new_pass else let fails = (acc... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_left (fun l e -> let (v1,v2,w) = e in if v1 = vertex then (v2,w)::l else l) [] g.edges;; let rec already_visited node visited = match visited with |[] -> false |h::t -> (h = node) || (already_visited node t) ;; |
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 (city,w) = node in let total = total + w in if city = b then (visited, total) else aux_list (neighbours g city) visited total and aux_list (nodes: ('a * 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 total: ('a list * weight)= let (city,w) = node in let total = total + w in if city = b then sc (visited, total) else aux_list (neighbours g city) visited fc sc total and aux_list (nodes: ('... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper p longest = match p with |[] -> Some longest |h::t -> let (cities,w) = h in let (best,price) = longest in if w > price then helper t h else helper t longest in let paths = find_all_paths g a b in if paths = [] then None els... |
let open_account (initial_pass: passwd) : bank_account = let pwd = ref initial_pass in let money = ref 0 in let err_times = ref 0 in let chk_pwd p = if !err_times >= 5 then raise too_many_failures else if !pwd = p then err_times := 0 else let () = err_times := !err_times + 1 in raise wrong_pass in let f1 pwd1 npwd = if... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.