RosettaCodeData/Task/Bell-numbers/Pluto/bell-numbers.pluto
2025-08-11 18:05:26 -07:00

32 lines
844 B
Text

local bigint = require "bigint"
local fmt = require "fmt"
local function bell_triangle(n)
local zero = bigint.new(0)
local tri = {}
for i = 1, n do
tri[i] = {}
for j = 1, i - 1 do tri[i][j] = zero end
end
tri[2][1] = bigint.new(1)
for i = 3, n do
tri[i][1] = tri[i - 1][i - 2]
for j = 2, i - 1 do
tri[i][j] = tri[i][j - 1] + tri[i - 1][j - 1]
end
end
return tri
end
local bt = bell_triangle(51)
print("First fifteen and fiftieth Bell numbers:")
for i = 2, 16 do
local s = bt[i][1]:tostring()
fmt.print("%2d: %s", i - 1, fmt.int(s))
end
local s50 = bt[51][1]:tostring()
fmt.print("%2d: %s", 50, fmt.int(s50))
print("\nThe first ten rows of Bell's triangle:")
for i = 2, 11 do
fmt.tprint("%7s", bt[i]:map(|j| -> fmt.int(j:tostring())), #bt[i])
end