Flat Asterisk Pyramid
Part of the Fundamentals section of Coddy's Ruby journey — lesson 86 of 88.
Challenge
EasyRead 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 resultAll lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Logical Operators Part 42Variables and Data Types
Numbers and VariablesString Data TypeBoolean Data TypeSymbol Data TypeChecking Data TypesNaming ConventionsRecap - Variable Creation8Loops
For Loop with RangesWhile LoopBreakNextRecap - FactorialTimes LoopUntil LoopNested LoopsRecap - Dynamic Input3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators6Basic IO
Output with putsOutput with print and pOutput With VariablesInput with getsChomp MethodType ConversionRecap - Age CalculatorRecap - True or False