text stringlengths 0 601k |
|---|
let fib (max : int) : int list = if max <= 1 then [] else unfold (fun b -> (fib_aux b 0 1,(b+1))) (fun b -> max <= fib_aux b 0 1) 0 ;; let rec lists l acc= match l with |[] -> acc |g :: [] -> acc |g::xs -> lists (xs) ((g+(List.nth xs 0))::acc) ;; let listb l = match l with | [] -> [1] | [1] -> [1;1] | g -> (List.append... |
let pascal (max : int) : int list list = if max = 0 then [] else unfold (fun b -> (listb b, listb b)) (fun b -> max <= (List.length b)) [] let zips (l1,l2)= match l1, l2 with | [], _ -> domain() | _, [] -> domain() | x::xs, y::ys -> ((x, y), (xs,ys)) ;; let listcheck l1 l2 = match l1, l2 with | [], _ -> true | _, [] ->... |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec exist1 x c1 = match x, c1 with |[], _ -> false |(g::gs, (Cupcake (x,y,z,e)))-> if (not (List.exists (fun e -> e != g) e)) then exist1 gs c1 else true in let existall l c = match l,c with |[], _ -> false |_, [] -> false |(g... |
let invalid_arg () = failwith "Invalid Argument";; let get = String.get ;; let append = (^);; let length = String.length ;; |
let string_explode (s : string) : char list = if length s < 1 then [] else tabulate (get s) (String.length s);; |
let string_implode (l : char list) : string = match l with |[] -> "" |g -> List.fold_left append "" (List.map Char.escaped l) let even b = if b mod 2 = 0 then (b, b+2) else (b+1, b+3);; |
let evens (max : int) : int list = if max < 0 then domain() else unfold (even) ((<=) max) 0 let rec fib_aux n a b = if n = 0 then b else fib_aux (n-1) (b) (a+b);; |
let fib (max : int) : int list = if max <= 1 then [] else unfold (fun b -> (fib_aux b 0 1,(b+1))) (fun b -> max <= fib_aux b 0 1) 0 ;; let rec lists l acc= match l with |[] -> acc |g :: [] -> acc |g::xs -> lists (xs) ((g+(List.nth xs 0))::acc) ;; let listb l = match l with | [] -> [1] | [1] -> [1;1] | g -> (List.append... |
let pascal (max : int) : int list list = if max = 0 then [] else unfold (fun b -> (listb b, listb b)) (fun b -> max <= (List.length b)) [] let zips (l1,l2)= match l1, l2 with | [], _ -> domain() | _, [] -> domain() | x::xs, y::ys -> ((x, y), (xs,ys)) ;; let listcheck l1 l2 = match l1, l2 with | [], _ -> true | _, [] ->... |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let rec exist1 x c1 = match x, c1 with |[], _ -> false |(g::gs, (Cupcake (x,y,z,e)))-> if (not(List.exists (fun e -> e != g) e)) then exist1 gs c1 else true in let existall l c = match l,c with |[], _ -> false |_, [] -> false |(g,... |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = List.fold_left (fun s c2 -> (s ^ (Char.escaped c2))) "" l;; |
let evens (max : int) : int list = unfold (fun en -> (en,en+2)) ((<=) max) 0;; |
let fib (max : int) : int list= unfold (fun (a,b)->((a+b),(b,a+b))) (fun b->max<=fst b + snd b) (1,0);; let cut=function |[]->[] |ls->(List.rev (List.tl (List.rev ls)));; let findNextRow ls= match (List.length ls) with |0->[1] |1->[1;1] |_->1::(List.map2 (+) (cut ls) (List.tl ls)) @ [1];; |
let pascal (max : int) : int list list = unfold (fun ls->let nextRow=findNextRow ls in (nextRow,nextRow)) (fun ls->List.length ls >= max) [];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let checkElement ins=not ( List.exists ((=)ins) allergens) in let checkCupcake cupCake= List.for_all (checkElement) (let Cupcake(_,_,_,ls)= cupCake in ls) in List.filter (checkCupcake) cupcakes;; |
let string_explode (s : string) : char list = tabulate (fun x -> String.get s x) (String.length s) ;; |
let string_implode (l : char list) : string = let k = List.map (fun x -> Char.escaped x) l in List.fold_left (^) "" k;; |
let evens (max : int) : int list = unfold (fun b -> (b, b+2)) (fun b -> max <= b) 0;; |
let fib (max : int) : int list = unfold (fun (a,b) -> (b, (b,a+b))) (fun (a,b) -> max <= b) (0,1);; |
let pascal (max : int) : int list list = raise NotImplemented;; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = raise NotImplemented;; |
let string_explode (s : string) : char list = tabulate (String.get s) (String.length s);; |
let string_implode (l : char list) : string = let add_char_to_string (s : string) (c : char) : string = s ^ (Char.escaped c) in List.fold_left (add_char_to_string) "" l;; |
let evens (max : int) : int list = let evens_list = unfold (fun b -> (b, b+2)) ((<=) max) 0 in evens_list;; |
let fib (max : int) : int list = let fibonacci_add (b : (int*int)) = let (b1,b2) = b in b1+b2, (b2, b1+b2) in let will_reach_max (b: (int*int)) = let (b1,b2) = b in max <= b2 + b1 in unfold (fibonacci_add) (will_reach_max) (1,0);; |
let pascal (max : int) : int list list = let generate_next_row (row : int list) = if List.length row >= 1 then let new_row = List.map2 (+) (0 :: row) (row @ [0]) in new_row, new_row else [1], [1] in let check_if_stop (row : int list) = List.length row + 1 > max in unfold (generate_next_row) (check_if_stop) [];; |
let allergy_free (allergens : ingredient list) (cupcakes : cupcake list) : cupcake list = let is_allergen (ing : ingredient) = not (List.exists (fun allergen -> allergen == ing) allergens) in let check_cupcake_ingredients (cup : cupcake) = let Cupcake (p,w,c,ings) = cup in List.for_all (is_allergen) ings in List.filter... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = ( fun oldP newP -> match oldP with | s when (s = !password) -> (attempts :=0 ; password := newP) | _ -> (attempts := !attempts +1 ; raise wrong_pass ) ) ; deposit = ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper (( (v1 : 'a) , (v2 : 'a) , (w : weight) ) as e) = match e with | (v,_,_) when (v=vertex) -> (@) [(v2, w)] | _ -> (@) [] in let e = g.edges in List.fold_right (helper) e [] ;; |
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 ( match aux_list (neighbours g n) (visited@[n]) with | (a1, w1) -> (a1, w1 + w) ) and aux_list (nodes: ('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)= let (a0, w0) = node in if (List.mem a0 visited) then (fc ()) else ( aux_list (neighbours g a0) (visited@[a0]) fc (fun (rv, r) -> sc (rv, (w0 + r) ) ) ) and aux_list (n... |
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 in let balance = ref 0 in let attempts = ref 0 in { update_pass = ( fun oldP newP -> match oldP with | s when (s = !password) -> (attempts :=0 ; password := newP) | _ -> (attempts := !attempts +1 ; raise wrong_pass ) ) ; deposit = ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper (( (v1 : 'a) , (v2 : 'a) , (w : weight) ) as e) = match e with | (v,_,_) when (v=vertex) -> (@) [(v2, w)] | _ -> (@) [] in let e = g.edges in List.fold_right (helper) e [] ;; |
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 ( match aux_list (neighbours g n) (visited@[n]) with | (a1, w1) -> (a1, w1 + w) ) and aux_list (nodes: ('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)= let (a0, w0) = node in if (List.mem a0 visited) then (fc ()) else ( aux_list (neighbours g a0) (visited@[a0]) fc (fun (rv, r) -> sc (rv, (w0 + r) ) ) ) and aux_list (n... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (all_paths: ('a list * weight) list) (acc_path: ('a list * weight) option) (acc_w: int) : (('a list * weight) option) = match all_paths with | [] -> acc_path | (path, w)::t when (w>acc_w)-> helper t (Some(path, w)) w | (pat... |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in { update_pass = ( fun oldP newP -> match oldP with | s when (s = !password) -> (attempts :=0 ; password := newP) | _ -> (attempts := !attempts +1 ; raise wrong_pass ) ) ; deposit = ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let helper (( (v1 : 'a) , (v2 : 'a) , (w : weight) ) as e) = match e with | (v,_,_) when (v=vertex) -> (@) [(v2, w)] | _ -> (@) [] in let e = g.edges in List.fold_right (helper) e [] ;; |
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 let (a1,w1) = aux_list (neighbours g n) (visited @ [n]) in (a1, (w1 + w)) and aux_list (nodes: ('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) fc sc : ('a list * weight)= let (a0, w0) = node in if (List.mem a0 visited) then (fc ()) else ( aux_list (neighbours g a0) (visited@[a0]) fc (fun (rv, r) -> sc (rv, (w0 + r) ) ) ) and aux_list (n... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let rec helper (all_paths: ('a list * weight) list) (acc_path: ('a list * weight) option) (acc_w: int) : (('a list * weight) option) = match all_paths with | [] -> acc_path | (path, w)::t when (w>acc_w)-> helper t (Some(path, w)) w | (pat... |
let open_account (initial_pass: passwd) : bank_account = let pw = ref initial_pass in let balance = ref 0 in let count = ref 0 in { update_pass = (fun (old_pw:passwd) (new_pw:passwd) -> if ((!pw) = old_pw) then let _ = count := 0 in pw := new_pw else let _ = count := !count+1 in raise wrong_pass ); retrieve = (fun cur_... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let rec helper edges v = match edges with | [] -> [] | (cur, tgt, weight)::tl -> if cur = v then (tgt, weight)::(helper tl v) else helper tl v in helper g.edges vertex ;; let rec contains l elt = match l with | [] -> false | hd::tl -> let (node, _) = elt ... |
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 (elt, weight) = node in if (elt = b) then ([b], weight) else let tgt = get_out_targets g.edges elt in let (res, wt) = (aux_list tgt visited) in (elt::res, wt+weight) and... |
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 (elt, weight) = node in if (elt = b) then sc ([elt], weight) else let tgt = get_out_targets g.edges elt in aux_list tgt visited fc (fun (res, wt) -> sc (elt::res, ... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let max = ref None in let rec helper list = match list with | [] -> !max | (res, wt)::tl -> match !max with | None -> let _ = max := Some (res, wt) in helper tl | Some (_, weight) -> if (wt > weight) then let _ = max := Some (res, wt) in ... |
let open_account (initial_pass: passwd) : bank_account = let acc_locked = ref false in let balance = ref 0 in let bad_attempts = ref 0 in let cur_pwd = ref initial_pass in { update_pass = (fun (old_pwd) (new_pwd) -> if old_pwd = !cur_pwd then let good_pwd = new_pwd in cur_pwd := good_pwd; bad_attempts := 0; acc_locked ... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let filtered_edges = List.filter (fun ((src:'a), _, _) -> src = vertex) g.edges in List.map (fun (_, (sink:'a), weight) -> (sink, weight)) filtered_edges;; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node_val, w):('a * weight)) (visited : 'a list) : ('a list * weight) = if List.mem node_val visited then raise Fail else if node_val = b then ([node_val], w) else let (lst, cur_w) = aux_list (neighbours g node_val) (node_val::visited)... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((node_val, w):('a * weight)) (visited : 'a list) fc sc : ('a list * weight) = if List.mem node_val visited then fc () else if node_val = b then (sc ([node_val], w)) else let succ = (fun (node_cont, w_cont) -> let (lst_sc, w_sc) = sc (... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let x = (find_all_paths g a b) in match x with | [] -> None | _ -> let n = List.hd (List.rev (List.sort (fun (_, w1) (_, w2) -> compare w1 w2) x)) in Some n;; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let fail_auth_count = ref 0 in let check_pass auth updating = if (!fail_auth_count >= 5) && not updating then (fail_auth_count := !fail_auth_count + 1; raise too_many_failures) else if not (auth = !passwor... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let proj (_, y, z) = (y, z) in let is_adjacent v (u, _, _) = v = u in List.map proj (List.filter (is_adjacent vertex) g.edges);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((u, w): 'a * weight) (visited : 'a list) : ('a list * weight)= if List.mem u visited then raise Fail else if u = b then ([u], w) else let recursion = aux_list (neighbours g u) (u :: visited) in (u :: (fst recursion), w + (snd recursion... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((u, w): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if List.mem u visited then fc () else if u = b then sc ([u], w) else let new_sc = fun x -> sc (u :: (fst x), w + (snd x)) in aux_list (neighbours g u) (u :: 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 | p :: l -> let r p1 p2 = let (_, w1) = p1 in let (_, w2) = p2 in if w2 > w1 then p2 else p1 in Some (List.fold_left r p l);; |
let open_account (initial_pass: passwd) : bank_account = let password = ref initial_pass in let balance = ref 0 in let fail_auth_count = ref 0 in let check_pass auth updating = if (!fail_auth_count >= 5) && not updating then raise too_many_failures else if not (auth = !password) then (fail_auth_count := !fail_auth_coun... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let proj (_, y, z) = (y, z) in let is_adjacent v (u, _, _) = v = u in List.map proj (List.filter (is_adjacent vertex) g.edges);; |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((u, w): 'a * weight) (visited : 'a list) : ('a list * weight)= if List.mem u visited then raise Fail else if u = b then ([u], w) else let recursion = aux_list (neighbours g u) (u :: visited) in (u :: (fst recursion), w + (snd recursion... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux_node ((u, w): 'a * weight) (visited : 'a list) fc sc : ('a list * weight)= if List.mem u visited then fc () else if u = b then sc ([u], w) else let new_sc = fun x -> sc (u :: (fst x), w + (snd x)) in aux_list (neighbours g u) (u :: 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 | p :: l -> let r p1 p2 = let (_, w1) = p1 in let (_, w2) = p2 in if w2 > w1 then p2 else p1 in Some (List.fold_left r p l);; |
let open_account (initial_pass: passwd) : bank_account = let failures = ref 0 in let balance = ref 0 in let password = ref (initial_pass:string) in let newAccount = { update_pass = ( fun input_pass new_pass -> if !password = input_pass then ( password := new_pass; failures := 0; ) else ( failures := !failures + 1; rais... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let tmp = List.fold_left n_helper (vertex, []) g.edges in match tmp with |a,b -> b |_ -> raise Fail;; let neighbours2 (g: 'a graph) (vertex: 'a) : ('a * weight) list = let tmp = List.fold_left n_helper (vertex, []) g.edges in match tmp with |a,b -> b |_ -... |
let find_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux (nd: 'a * weight) (visited : ('a * weight) list) (result: ('a * weight) list):(('a * weight) list) = let node = match nd with a,b -> a in let nodeWeight = match nd with a,b -> b in try ( let adjacent = neighbours g node in match List.find (h... |
let find_path' (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) = let rec aux (nd: 'a * weight) (visited : ('a * weight) list) (k: ('a * weight) list -> ('a * weight) list):(('a * weight) list) = let node = match nd with a,b -> a in let nodeWeight = match nd with a,b -> b in let adjacent = neighbours2 g node in let (... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let pathsList = find_all_paths g a b in let sortedList = List.rev (List.sort sortPaths pathsList) in let res = try List.hd sortedList with Failure "hd" -> ([],0) in match res with | [],_ -> None | _ -> Some res ;; |
let open_account (initial_pass: passwd) : bank_account = let pass = ref initial_pass in let balance = ref 0 in let attempts = ref 0 in let check_pass p f = if p = !pass then (attempts := 0; f ()) else (incr attempts; raise wrong_pass) in let attempt p f = if !attempts >= 5 then raise too_many_failures else check_pass p... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = List.fold_right (fun (x, y, w) acc -> if x = vertex then (y,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 (x, y) = node in if x = b then ([b] , y) else if List.mem x visited then raise Fail else (let (path , cost) = aux_list (neighbours g x) (x :: visited) in (x :: path, cos... |
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 (x, y) = node in if x = b then sc ([b], y) else if List.mem x visited then fc () else aux_list (neighbours g x) (x :: visited) fc (fun (path, cost) -> sc (x :: pat... |
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 passwd = ref initial_pass in let count = ref 0 in let balance = ref 0 in {update_pass = (fun old_pass new_pass -> (match old_pass = !passwd with |true -> passwd := new_pass; count := 0 |false -> count := !count + 1; raise wrong_pass)); retrieve = (fun pass am... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge l (a, b, w) = if a = vertex then (b, w) :: l else l in List.fold_left edge [] 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 (a', w) = node in if List.mem a' visited then raise Fail else match b with |[] -> raise Fail |node::_ -> if a' = b then ([], 0) else let n = (neighbours g a') in aux_lis... |
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 passwd = ref initial_pass in let count = ref 0 in let balance = ref 0 in {update_pass = (fun old_pass new_pass -> (match old_pass = !passwd with |true -> passwd := new_pass; count := 0 |false -> count := !count + 1; raise wrong_pass)); retrieve = (fun pass am... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let edge l (a, b, w) = if a = vertex then (b, w) :: l else l in List.fold_left edge [] 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 (a', w) = node in if List.mem a' visited then raise Fail else match a' = b with |true -> ([a'], w) |false -> let n = (neighbours g a') in aux_list n (a' :: visited) and ... |
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 num_fails = ref 0 in let password = ref initial_pass in let pass_fail = (fun () -> if !num_fails >= 5 then raise too_many_failures else (num_fails := !num_fails + 1 ; raise wrong_pass)) in { update_pass = (fun old_pass new_pass -> if (o... |
let neighbours (g: 'a graph) (vertex: 'a) : ('a * weight) list = let desired_edges = List.find_all (fun (x,y,w) -> x = vertex) g.edges in List.map get_2_3 desired_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 (get_1 node) = b then ([get_1 node], (get_2 node)) else let unvisited : ('a * weight) list = List.filter (fun (x,_) -> not (List.mem x visited)) (neighbours g (get_1 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)= if (get_1 node) = b then sc (node) else let unvisited : ('a * weight) list = List.filter (fun (x,_) -> not (List.mem x visited)) (neighbours g (get_1 node)) in match u... |
let find_longest_path (g: 'a graph) (a: 'a) (b: 'a) : ('a list * weight) option = let compare path1 path2 = if (get_2 path1) > (get_2 path2) then path1 else path2 in let all_paths = find_all_paths g a b in match all_paths with | [] -> None | x::xs -> Some (List.fold_right compare xs x);; |
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 (p: passwd): bool = if (!attempts <= 3) then if (p = !password) then (attempts := 0; true) else (attempts := !attempts+1; raise wrong_pass) else raise too_many_failures i... |
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 and password = ref initial_pass and attempts = ref 0 in let check_passwd (p: passwd): bool = if (!attempts <= 5) then if (p = !password) then (attempts := 0; true) else (attempts := !attempts+1; raise wrong_pass) else raise too_many_failures i... |
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 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 ;; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.