Last active
March 12, 2017 11:36
-
-
Save dengsauve/6ffde2ba87f0920fea2aff3eeb105985 to your computer and use it in GitHub Desktop.
Right_triangle.rb created by dengsauve
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 "How long are the sides?: " | |
side_length = gets.chomp.to_i | |
if side_length > 0 | |
puts "*" | |
(side_length - 2).times { |i| puts "*" + (" " * i) + "*" } | |
puts "*" * side_length | |
side_length.times { |i| (i+1).times { |n| print (n+1).to_s.rjust(side_length.to_s.length) }; puts } | |
puts " " * (side_length - 1) + "*" | |
(side_length - 2).times { |i| puts " " * (side_length - (i + 2)) + "*" + (" " * i) + "*" } | |
puts "*" * side_length | |
else | |
puts "Please enter an integer greater than 0." | |
end | |
if side_length > 1 | |
line_length = (side_length * 2) | |
puts "*".rjust(line_length / 2) | |
(side_length - 1).times { |i| puts ("*"+(" " * ((i*2)+1))+"*").rjust((line_length/2)+i+1) } | |
(side_length-3).downto(0) { |i| puts ("*"+(" " * ((i*2)+1))+"*").rjust((line_length/2)+i+1) } | |
puts "*".rjust(line_length / 2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment