Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- type 'a bin_tree =
- | Red of 'a bin_tree * 'a * 'a bin_tree
- | Blue of 'a bin_tree * 'a * 'a bin_tree
- | Nil
- let more_blue tree =
- let rec aux sums = function
- | Blue (l, _, r) -> qor sums (1, 0) (aux sums l) (aux sums r)
- | Red (l, _, r) -> qor sums (0, 1) (aux sums l) (aux sums r)
- | Nil -> sums
- and qor (a, b) (c, d) (e, f) (g, h) = (a + c + e + g, b + d + f + h) in
- let blues, reds = aux (0, 0) tree in
- blues > reds
- let rbt = Red (Blue (Blue(Nil, 4, Red (Nil, 11, Nil)), 1, Nil), 8, Red (Nil, 4, Blue(Nil, 7, Blue (Nil, 4, Nil))))
- let () = more_blue rbt |> string_of_bool |> print_endline
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement