From 84e6753005e57827c78b50ad0a26ffa0d0da55e4 Mon Sep 17 00:00:00 2001 From: Joe Zhao Date: Mon, 6 Apr 2015 13:53:37 +0800 Subject: +59 +60 --- H60.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 H60.hs (limited to 'H60.hs') diff --git a/H60.hs b/H60.hs new file mode 100644 index 0000000..6f3f1b0 --- /dev/null +++ b/H60.hs @@ -0,0 +1,18 @@ +import Tree +import H59 + +import Data.Maybe +import Data.List + +hbalTreeNodes :: Int -> [Tree Char] +hbalTreeNodes 0 = [Empty] +hbalTreeNodes n = concatMap (filter ((==n).countNodes).hbalTree') [minH..maxH] + where + -- Shenle + minNodesSeq = 0:1:zipWith ((+).(1+)) minNodesSeq (tail minNodesSeq) + + minH = ceiling $ logBase 2 $ fromIntegral (n+1) + maxH = (fromJust $ findIndex (>n) minNodesSeq) - 1 + countNodes Empty = 0 + countNodes (Branch _ t1 t2) = 1 + (countNodes t1) + (countNodes t2) + -- cgit v1.2.3-70-g09d2