RosettaCodeData/Task/Floyds-triangle/Sidef/floyds-triangle.sidef

11 lines
288 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

func floyd(rows, n=1) {
var max = Math.range_sum(1, rows)
var widths = (max-rows .. max-1 -> map{.+n->to_s.len})
{ |r|
say %'#{1..r -> map{|i| "%#{widths[i-1]}d" % n++}.join(" ")}'
} << 1..rows
}
floyd(5) # or: floyd(5, 88)
floyd(14) # or: floyd(14, 900)