Bell numbers: Difference between revisions

Add CLU
(Add CLU)
Line 708:
21147 25287 30304 36401 43833 52922 64077 77821 94828 115975
</pre>
 
=={{header|CLU}}==
<lang clu>bell = cluster is make, get
rep = array[int]
idx = proc (row, col: int) returns (int)
return (row * (row - 1) / 2 + col)
end idx
get = proc (tri: cvt, row, col: int) returns (int)
return (tri[idx(row, col)])
end get
 
make = proc (rows: int) returns (cvt)
length: int := rows * (rows+1) / 2
arr: rep := rep$fill(0, length, 0)
arr[idx(1,0)] := 1
for i: int in int$from_to(2, rows) do
arr[idx(i,0)] := arr[idx(i-1, i-2)]
for j: int in int$from_to(1, i-1) do
arr[idx(i,j)] := arr[idx(i,j-1)] + arr[idx(i-1,j-1)]
end
end
return(arr)
end make
end bell
 
start_up = proc ()
rows = 15
po: stream := stream$primary_output()
belltri: bell := bell$make(rows)
stream$putl(po, "The first 15 Bell numbers are:")
for i: int in int$from_to(1, rows) do
stream$putl(po, int$unparse(i)
|| ": " || int$unparse(bell$get(belltri, i, 0)))
end
stream$putl(po, "\nThe first 10 rows of the Bell triangle:")
for row: int in int$from_to(1, 10) do
for col: int in int$from_to(0, row-1) do
stream$putright(po, int$unparse(bell$get(belltri, row, col)), 7)
end
stream$putc(po, '\n')
end
end start_up</lang>
{{out}}
<pre>The first 15 Bell numbers are:
1: 1
2: 1
3: 2
4: 5
5: 15
6: 52
7: 203
8: 877
9: 4140
10: 21147
11: 115975
12: 678570
13: 4213597
14: 27644437
15: 190899322
 
The first 10 rows of the Bell triangle:
1
1 2
2 3 5
5 7 10 15
15 20 27 37 52
52 67 87 114 151 203
203 255 322 409 523 674 877
877 1080 1335 1657 2066 2589 3263 4140
4140 5017 6097 7432 9089 11155 13744 17007 21147
21147 25287 30304 36401 43833 52922 64077 77821 94828 115975</pre>
 
=={{header|Common Lisp}}==
2,115

edits