Stirling numbers of the first kind: Difference between revisions
Content added Content deleted
(Added Wren) |
|||
Line 1,370: | Line 1,370: | ||
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000 |
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000 |
||
(158 digits, k = 5)</pre> |
(158 digits, k = 5)</pre> |
||
=={{header|Wren}}== |
|||
{{trans|Java}}{{libheader|Wren-big}} |
|||
{{libheader|Wren-fmt}} |
|||
<lang ecmascript>import "/big" for BigInt |
|||
import "/fmt" for Fmt |
|||
var computed = {} |
|||
var stirling1 // recursive |
|||
stirling1 = 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) return BigInt.zero |
|||
if (k > n) return BigInt.zero |
|||
var result = stirling1.call(n-1, k-1) + stirling1.call(n-1, k)*(n-1) |
|||
computed[key] = result |
|||
return result |
|||
} |
|||
System.print("Unsigned Stirling numbers of the first 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", stirling1.call(n, k)) |
|||
System.print() |
|||
} |
|||
System.print("The maximum value of S1(100, k) =") |
|||
var previous = BigInt.zero |
|||
for (k in 1..100) { |
|||
var current = stirling1.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 first 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 2 3 1 |
|||
4 0 6 11 6 1 |
|||
5 0 24 50 35 10 1 |
|||
6 0 120 274 225 85 15 1 |
|||
7 0 720 1764 1624 735 175 21 1 |
|||
8 0 5040 13068 13132 6769 1960 322 28 1 |
|||
9 0 40320 109584 118124 67284 22449 4536 546 36 1 |
|||
10 0 362880 1026576 1172700 723680 269325 63273 9450 870 45 1 |
|||
11 0 3628800 10628640 12753576 8409500 3416930 902055 157773 18150 1320 55 1 |
|||
12 0 39916800 120543840 150917976 105258076 45995730 13339535 2637558 357423 32670 1925 66 1 |
|||
The maximum value of S1(100, k) = |
|||
19710908747055261109287881673376044669240511161402863823515728791076863288440277983854056472903481625299174865860036734731122707870406148096000000000000000000 |
|||
(158 digits, k = 5) |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |