From 626a548f0ef51b5ee1d3ba049330317f94c89f99 Mon Sep 17 00:00:00 2001 From: Determinant Date: Tue, 30 May 2017 01:28:36 -0400 Subject: ... --- 61-69/65.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 61-69/65.hs (limited to '61-69/65.hs') diff --git a/61-69/65.hs b/61-69/65.hs new file mode 100644 index 0000000..179b972 --- /dev/null +++ b/61-69/65.hs @@ -0,0 +1,16 @@ +data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show, Eq) + +layout :: Tree Char -> Tree (Char, (Int, Int)) + +layout t = draw t (1 + 2 ^ (dep - 1) - 2 ^ (dep - ldep)) 1 (2 ^ (dep - 2)) + where depth Empty = 0 + depth (Branch _ l r) = 1 + max (depth l) (depth r) + ldepth Empty = 0 + ldepth (Branch _ l _) = 1 + ldepth l + dep = depth t + ldep = ldepth t + draw Empty _ _ _ = Empty + draw (Branch v l r) x y h = Branch (v, (x, y)) lt rt + where h' = h `div` 2 + lt = draw l (x - h) (y + 1) h' + rt = draw r (x + h) (y + 1) h' -- cgit v1.2.3