Stirling numbers of the second kind: Difference between revisions

Added Wren
m (→‎{{header|REXX}}: added/changed whitespace and comments, expaciated the title for the "row".)
(Added Wren)
Line 1,399:
7769730053598745155212806612787584787397878128370115840974992570102386086289805848025074822404843545178960761551674
(115 digits, k = 28)</pre>
 
=={{header|Wren}}==
{{trans|Java}}
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
<lang ecmascript>import "/big" for BigInt
import "/fmt" for Fmt
 
var computed = {}
 
var stirling2 // recursive
stirling2 = Fn.new { |n, k|
var key = "%(n),%(k)"
if (computed.containsKey(key)) return computed[key]
if (n == 0 && k == 0) return BigInt.one
if ((n > 0 && k == 0) || (n == 0 && k > 0)) return BigInt.zero
if (k == n) return BigInt.one
if (k > n) return BigInt.zero
var result = stirling2.call(n-1, k-1) + stirling2.call(n-1, k)*k
computed[key] = result
return result
}
 
System.print("Unsigned Stirling numbers of the second kind:")
var max = 12
System.write("n/k")
for (n in 0..max) Fmt.write("$10d", n)
System.print()
for (n in 0..max) {
Fmt.write("$-3d", n)
for (k in 0..n) Fmt.write("$10i", stirling2.call(n, k))
System.print()
}
System.print("The maximum value of S2(100, k) =")
var previous = BigInt.zero
for (k in 1..100) {
var current = stirling2.call(100, k)
if (current > previous) {
previous = current
} else {
Fmt.print("$i\n($d digits, k = $d)", previous, previous.toString.count, k - 1)
break
}
}</lang>
 
{{out}}
<pre>
Unsigned Stirling numbers of the second kind:
n/k 0 1 2 3 4 5 6 7 8 9 10 11 12
0 1
1 0 1
2 0 1 1
3 0 1 3 1
4 0 1 7 6 1
5 0 1 15 25 10 1
6 0 1 31 90 65 15 1
7 0 1 63 301 350 140 21 1
8 0 1 127 966 1701 1050 266 28 1
9 0 1 255 3025 7770 6951 2646 462 36 1
10 0 1 511 9330 34105 42525 22827 5880 750 45 1
11 0 1 1023 28501 145750 246730 179487 63987 11880 1155 55 1
12 0 1 2047 86526 611501 1379400 1323652 627396 159027 22275 1705 66 1
The maximum value of S2(100, k) =
7769730053598745155212806612787584787397878128370115840974992570102386086289805848025074822404843545178960761551674
(115 digits, k = 28)
</pre>
 
=={{header|zkl}}==
9,490

edits