Created
May 2, 2013 17:08
-
-
Save Rleahy22/5503710 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
# 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