Output triangle in Ruby

I touched Ruby for the first time in class today, so I recorded it as a memorial. The problem of creating the following triangle with only the output of ○.              ○          ○○○       ○○○○○    ○○○○○○○

n = gets.to_i #input

for x in 1..n
    (n-x).times{print(" ")} #The number of blanks is n-Decrease by 1 from the number of 1
    for y in 1..2*(x-1)+1 #The number of ○ is 2*(x-1)+1

First, the blank space on the left side of the circle is output, and then the circle is output. Then, when the output of the circle was finished, I wrote the program in the flow of putting a line break with puts. The number of blanks that can be created on the left side is n-1 in the first row, and is incremented by -1 thereafter. The number of ○ is calculated by 2 (x-1) + 1. When I put the above into the program, I was able to output it safely.

I'm confused because different languages have different specifications, but I want to get used to it quickly.

Recommended Posts

Output triangle in Ruby
String output method memo in Ruby
Ruby input / output
[ruby] drill output
[ruby] drill output
Ruby standard output
[ruby] drill output
[ruby] drill output
[ruby] drill output
[ruby] drill output
Heavy in Ruby! ??
About eval in Ruby
Ruby calorie calculation output
Variable type in ruby
Output in multiples of 3
Fast popcount in Ruby
[Ruby] How to use standard output in conditional branching
ABC177 --solving E in Ruby
Validate JWT token in Ruby
Implemented XPath 1.0 parser in Ruby
Read design patterns in Ruby
Write class inheritance in Ruby
Integer unified into Integer in Ruby 2.4
Multiplication in a Ruby array
About regular expressions in Ruby
Birthday attack calculation in Ruby
Supports 0 drop in CSV output
Judgment of fractions in Ruby
Find Roman numerals in Ruby
Try using gRPC in Ruby
[Ruby] Find numbers in arrays
NCk mod p in Ruby
Chinese Remainder Theorem in Ruby
Sorting hashes in a Ruby array
Basics of sending Gmail in Ruby
How to iterate infinitely in Ruby
Output JavaScript in Thymeleaf 3 without escaping
Achieve 3-digit delimited display in Ruby
Encoding when getting in Windows + Ruby
Run GraphQL Ruby resolver in parallel
Ruby on Rails Japanese-English support i18n
[Ruby] Extracting double hash in array
[Ruby on Rails] CSV output function
Mixed Western calendar output in Java
Implement a gRPC client in Ruby
Log output to file in Java
Write keys and values in Ruby
[Super Introduction] About Symbols in Ruby
Hanachan in Ruby (non-destructive array manipulation)
Manipulating data in GCS during Ruby
Output JUnit test report in Maven
Is there no type in Ruby?
Try file locking in Ruby directory
[Ruby] undefined method `dark?'occurs in rqr_code
openssl version information in ruby OPENSSL_VERSION
Ruby methods often used in Rails
Make Ruby segfault in two lines
[Ruby] I want to output only the odd-numbered characters in the character string
I tried a calendar problem in Ruby
Implementing poker little by little in Ruby Part 2
How to get date data in Ruby