Created
March 10, 2014 17:07
-
-
Save tom-galvin/9469282 to your computer and use it in GitHub Desktop.
DailyProgrammer Challenge #145 Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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