-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathprint_triangle.rb
More file actions
46 lines (35 loc) · 1.12 KB
/
Copy pathprint_triangle.rb
File metadata and controls
46 lines (35 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# Method name: print_triangle
# Input: a number n
# Returns: Nothing
# Prints: a right triangle consisting of "*" characters that is "n"
# characters tall
#
# For example, print_triangle(4) should print
#
# *
# **
# ***
# ****
# The print_line method is here to help you.
# Conceptually, it prints out a row of "count" *'s. Run it yourself to
# see how it works. Experiment with different inputs.
def print_line(count)
(1..count).each do |i|
print "*" # This prints a single "*"
end
print "\n" # This forces the output to the next line, like hitting "return"
end
def print_triangle(height)
# You have to fill in the details here.
end
# There are no rumble strips this time. It's up to you to decide whether
# this is working as intended or not.
if __FILE__ == $PROGRAM_NAME
print_triangle(1)
print "\n\n\n" # This is here to make the separation between triangles clearer
print_triangle(2)
print "\n\n\n" # This is here to make the separation between triangles clearer
print_triangle(3)
print "\n\n\n" # This is here to make the separation between triangles clearer
print_triangle(10)
end