Editor

Floyd's Triangle

#566 · Loops · Beginner · 35 XP · about 6 min

Floyd's triangle writes the numbers 1, 2, 3 and so on in rows that grow by one each time: one number in row 1, two numbers in row 2, three in row 3, and so on. The counting never starts again: each row carries on from where the row before stopped.

Write floyd(rows) that returns the first rows rows as a list of strings, with the numbers in each row separated by single spaces. For rows = 0 return an empty list.

Examples

floyd(4)  # returns ['1', '2 3', '4 5 6', '7 8 9 10']
floyd(1)  # returns ['1']
floyd(0)  # returns []

Fastest solvers

Leaderboard

First solves only, ranked by stars and then time.