11 lines
288 B
Text
11 lines
288 B
Text
|
|
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)
|