Skip to content

Instantly share code, notes, and snippets.

@Rleahy22
Created May 2, 2013 17:08
Show Gist options
  • Save Rleahy22/5503710 to your computer and use it in GitHub Desktop.
Save Rleahy22/5503710 to your computer and use it in GitHub Desktop.
# print_triangle(rows) prints out a right triangle of +rows+ rows consisting
# of * characters
#
# +rows+ is an integer
#
# For example, print_triangle(4) should print out the following:
# *
# **
# ***
# ****
def print_triangle(rows)
if rows == 0
return nil
else
triangle = ""
(1..rows).each do |i|
triangle << "#{**i}"
end
end
puts triangle
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment