RosettaCodeData/Task/Floyds-triangle/Ruby/floyds-triangle.rb

12 lines
229 B
Ruby
Raw Permalink Normal View History

2014-01-17 05:32:22 +00:00
def floyd(rows)
max = (rows * (rows + 1)) / 2
widths = ((max - rows + 1)..max).map {|n| n.to_s.length + 1}
n = 0
rows.times do |r|
puts (0..r).map {|i| n += 1; "%#{widths[i]}d" % n}.join
2013-04-10 21:29:02 -07:00
end
end
2014-01-17 05:32:22 +00:00
floyd(5)
floyd(14)