Skip to content

Instantly share code, notes, and snippets.

@tom-galvin
Created March 10, 2014 17:07
Show Gist options
  • Save tom-galvin/9469282 to your computer and use it in GitHub Desktop.
Save tom-galvin/9469282 to your computer and use it in GitHub Desktop.
DailyProgrammer Challenge #145 Solution
# reddit.com/r/DailyProgrammer
# Solution to Challenge #145: Tree Generation
def print_tree(n, trunk, leaves)
(1..n).step(2) do |a|
side_spaces = " " * ((n - a) / 2)
puts side_spaces + leaves * a
end
puts " " * ((n - 3) / 2) + trunk * 3
end
print_tree(7, "#", "|") # Example Usage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment