Facebook
From Red Rhinoceros, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 92
  1. type color = W | B
  2. type image = L of color * int
  3.            | N of image * image * image * image
  4. Tree:
  5. N (L (W, 4), N (L (W, 1), L (B, 1), L (W, 1), L (B, 2)),
  6.  N (L (W, 2), L (W, 2), L (W, 2), L (B, 1)), L (B, 4))
  7.  
  8. Tree to array:
  9. let tree_to_array tr n =
  10.   match tr with
  11.   | L(a, b) -> Array.make_matrix n n (leaf_bit a)
  12.   | N(a, b, c, d) -> quad_arr_append (tree_to_array a (n/2)) (tree_to_array b (n/2)) (tree_to_array c (n/2)) (tree_to_array d (n/2))
  13.