blob: 3d44ac3129d029357ca27a96cf5301f31bf9b4fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
module H59 where
import Tree
hbalTree :: Int -> [Tree Char]
hbalTree 0 = [Empty]
hbalTree h = [Branch 'x' x y | let tl = concatMap hbalTree $ filter (>=0) [h-2,h-1],x <- tl, y <- tl]
hbalTree' 1 = [Branch 'x' Empty Empty]
hbalTree' h = hbalhelper (h-1) [Branch 'x' Empty Empty] [Empty]
where
hbalhelper 0 x _ = x
hbalhelper n x y = hbalhelper (n-1) [Branch 'x' l r| let tl = x ++ y, l <- tl, r <- tl] x
|