2016-12-05 23:44:36 +01:00
|
|
|
|
func floyd(rows, n=1) {
|
2017-09-23 10:01:46 +02:00
|
|
|
|
var max = Math.range_sum(1, rows)
|
|
|
|
|
|
var widths = (max-rows .. max-1 -> map{.+n->to_s.len})
|
2016-12-05 23:44:36 +01:00
|
|
|
|
{ |r|
|
2017-09-23 10:01:46 +02:00
|
|
|
|
say %'#{1..r -> map{|i| "%#{widths[i-1]}d" % n++}.join(" ")}'
|
|
|
|
|
|
} << 1..rows
|
2016-12-05 23:44:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-23 10:01:46 +02:00
|
|
|
|
floyd(5) # or: floyd(5, 88)
|
|
|
|
|
|
floyd(14) # or: floyd(14, 900)
|