Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2021
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.60 KB | None | 0 0
  1. type 'a bin_tree =
  2.     | Red of 'a bin_tree * 'a * 'a bin_tree
  3.     | Blue of 'a bin_tree * 'a * 'a bin_tree
  4.     | Nil
  5.  
  6. let more_blue tree =
  7.     let rec aux sums = function
  8.         | Blue (l, _, r) -> qor sums (1, 0) (aux sums l) (aux sums r)
  9.         | Red (l, _, r) -> qor sums (0, 1) (aux sums l) (aux sums r)
  10.         | Nil -> sums
  11.     and qor (a, b) (c, d) (e, f) (g, h) = (a + c + e + g, b + d + f + h) in
  12.     let blues, reds = aux (0, 0) tree in
  13.     blues > reds
  14.  
  15. let rbt = Red (Blue (Blue(Nil, 4, Red (Nil, 11, Nil)), 1, Nil), 8, Red (Nil, 4, Blue(Nil, 7, Blue (Nil, 4, Nil))))
  16.  
  17. let () = more_blue rbt |> string_of_bool |> print_endline
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement