Skip to content

Commit 09f0c04

Browse files
committed
Printed the asterisk on an inverted pyramid grid-like format
1 parent 6d8366f commit 09f0c04

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

exercises/print_pyramid.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,29 @@ def print_pyramid(height)
2525
# Suggestion: you can call print_triangle to print out the first, "upward"
2626
# half of the pyramid. You'll have to write code to print out the second,
2727
# "downward" half of the pyramid.
28+
29+
print_triangle(height)
30+
height.downto(1) do |i| # or, equivalently, reverse the range from height to 1
31+
print_line(i) # I called the print_line method to repeat the same process as in print_triangle.rb
32+
33+
end
34+
2835
end
2936

3037
if __FILE__ == $PROGRAM_NAME
3138
# I'd advise putting some sanity checks here.
3239
# How else will you be sure your code does what you think it does?
40+
print_pyramid(1)
41+
42+
print "\n\n\n" # This is here to make the separation between pyramids clearer
43+
44+
print_pyramid(2)
45+
46+
print "\n\n\n" # This is here to make the separation between pyramids clearer
47+
48+
print_pyramid(3)
49+
50+
print "\n\n\n" # This is here to make the separation between pyramids clearer
51+
52+
print_pyramid(10)
3353
end

0 commit comments

Comments
 (0)