Skip to content

Instantly share code, notes, and snippets.

@TheNotary
Created January 25, 2013 03:07
Show Gist options
  • Save TheNotary/4631402 to your computer and use it in GitHub Desktop.
Save TheNotary/4631402 to your computer and use it in GitHub Desktop.
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