Mercurial > repos > rhope
view binary_trees.rhope @ 103:7428aa5d6ade
Compiler compiled by compiler sort of working
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 11 Aug 2010 03:13:28 -0400 |
parents | f4fd8962c385 |
children | d59611dcec71 |
line wrap: on
line source
Blueprint Tree { Left Right Item } Blueprint Empty { } Make Tree[item,depth:out] { If[depth] { dbl <- [item]+[item] ndepth <- [depth]-[1] out <- [[[Build[Tree()]]Left <<[ Make Tree[[dbl]-[1], ndepth] ]]Right <<[ Make Tree[dbl, ndepth] ]]Item <<[item] }{ out <- [[[Build[Tree()]]Left <<[Build[Empty()]]]Right <<[Build[Empty()]]]Item <<[item] } } Check Tree@Tree[node:out] { out <- [[[node]Item >>]+[Check Tree[[node]Left >>]]] - [Check Tree[[node]Right >>]] } Check Tree@Empty[node:out] { out <- 0 } Step[num, depth: out] { out <- [Check Tree[Make Tree[num, depth]]] + [Check Tree[Make Tree[[0]-[num], depth]]] } Test Size[sum, current,iterations,depth:out] { nsum <- [sum]+[Step[current, depth]] If[[current]=[iterations]] { out <- Val[nsum] }{ out <- Test Size[nsum, [current]+[1], iterations, depth] } } Test Sizes[current,max,iterations:out] { sum <- Test Size[0, 1, iterations, current] { Print[ [[[[String[[iterations]*[2]] ]Append["\t trees of depth "] ]Append[String[current]] ]Append["\t check: "] ]Append[String[sum]]] { If[[current]=[max]] { out <- 1 }{ out <- Test Sizes[[current]+[2], max, [iterations]/[4]] } } } } Main[args] { [args]Index[1] { min depth <- 4 max depth <- Max[[min depth]+[2], Int32[~]] Print[ [[["stretch tree of depth " ]Append[String[[max depth]+[1]]] ]Append["\t check: "] ]Append[String[Check Tree[Make Tree[0, [max depth]+[1]]]]]] { long lived <- Make Tree[0, max depth] { Test Sizes[min depth, max depth, [1]LShift[max depth]] { Print[ [[["long lived tree of depth " ]Append[String[max depth]] ]Append["\t check: "] ]Append[String[Check Tree[long lived]]]] }}} }{ Print["you must provide a max depth param"] } }