Menu
Coddy logo textTech

Flat Asterisk Pyramid

Part of the Fundamentals section of Coddy's Ruby journey — lesson 86 of 88.

challenge icon

Challenge

Easy

Read a number n from input and print a flat asterisk pyramid on a single line.

The pyramid consists of groups of asterisks where the first group has 1 asterisk, the second has 2, the third has 3, and so on up to n asterisks. Each group is separated by a single space.

Use string multiplication ("*" * count) to create each group of asterisks, and build the complete pattern before printing it.

For example, if the input is 5, the output should be:

* ** *** **** *****

If the input is 3, the output should be:

* ** ***

If the input is 1, the output should be:

*

Try it yourself

# Read the number n from input
n = gets.to_i

# TODO: Write your code below
# Use a loop to build the pyramid pattern
# Each group should have increasing asterisks (1, 2, 3, ... n)
# Use string multiplication ("*" * count) to create each group
# Separate groups with a single space


# Output the result
puts result

All lessons in Fundamentals