Bell numbers: Difference between revisions

Content deleted Content added
Added Algol 68
PureFox (talk | contribs)
→‎{{header|Wren}}: BigInt support added since original solution posted.
Line 3,520:
{{trans|Go}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/big" for BigInt
Unable to calculate 50th Bell number accurately due to lack of 'big integer' support.
<lang ecmascript>import "/fmt" for Fmt
 
var bellTriangle = Fn.new { |n|
var tri = List.filled(n, []null)
for (i in 0...n) tri[i] = List.filled(i, 0){
tri[1][0i] = 1List.filled(i, null)
for (j in 0...i) tri[i][j] = BigInt.zero
}
tri[1][0] = BigInt.one
for (i in 2...n) {
tri[i][0] = tri[i-1][i-2]
Line 3,536 ⟶ 3,539:
}
 
var bt = bellTriangle.call(1651)
System.print("First fifteen and fifitieth Bell numbers:")
for (i in 1..15) SystemFmt.print("%(Fmt.$d(2: $,i", i)):, %(bt[i][0])")
Fmt.print("$d: $,i", 50, bt[50][0])
System.print("\nThe first ten rows of Bell's triangle:")
for (i in 1..10) SystemFmt.print("$,7i", bt[i])</lang>
 
{{out}}
<pre>
First fifteen and fifitieth Bell numbers:
1: 1
2: 1
3: 2
4: 5
5: 15
6: 52
7: 203
8: 877
9: 41404,140
10: 2114721,147
11: 115975115,975
12: 678570678,570
13: 42135974,213,597
14: 2764443727,644,437
15: 190899322190,899,322
50: 10,726,137,154,573,358,400,342,215,518,590,002,633,917,247,281
 
The first ten rows of Bell's triangle:
1
[1]
1 2
[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 1,080 1335 1,335 1657 1,657 2066 2,066 2589 2,589 3263 3,263 4140] 4,140
4,140 5,017 6,097 7,432 9,089 11,155 13,744 17,007 21,147
[4140, 5017, 6097, 7432, 9089, 11155, 13744, 17007, 21147]
21,147 25,287 30,304 36,401 43,833 52,922 64,077 77,821 94,828 115,975
[21147, 25287, 30304, 36401, 43833, 52922, 64077, 77821, 94828, 115975]
</pre>