Skip to content

Instantly share code, notes, and snippets.

@mkrogemann
Created June 9, 2013 01:20
Show Gist options
  • Select an option

  • Save mkrogemann/5737216 to your computer and use it in GitHub Desktop.

Select an option

Save mkrogemann/5737216 to your computer and use it in GitHub Desktop.
'Tannenbaum' in groovy. Tests?
def tree(height, with_star = true) {
if (with_star) println(" " * (left_padding(height, 0) - 1) + "*")
(1..height).each {
ring(it, height)
}
println(" " * (left_padding(height, 0) - 1) + "X")
}
def ring(from_top, height) {
println(" " * left_padding(height, from_top) + "X" * (2 * from_top - 1))
}
def left_padding(height, from_top) {
height - from_top
}
tree(15)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment