Created
January 25, 2013 03:07
-
-
Save TheNotary/4631402 to your computer and use it in GitHub Desktop.
This file contains 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
def print_triangle(size) | |
print_top_row_of_triangle(size) | |
return if size <= 1 | |
print_middle_section_of_triangle(size) | |
print_bottom_of_triangle(size) | |
end | |
def print_top_row_of_triangle(size) | |
puts "*" if size >= 1 | |
end | |
def print_middle_section_of_triangle(size) | |
row_count = 0 | |
(size-2).times do | |
puts "*" + " "*row_count + "*" | |
row_count += 1 | |
end | |
end | |
def print_bottom_of_triangle(size) | |
puts "*" * size | |
end | |
print "Enter the size of triangle: " | |
size = gets.to_i | |
print_triangle(size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment