Paraffins: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed wording in the REXX section header.) |
(Added Wren) |
||
Line 3,477: | Line 3,477: | ||
puts "${n}: [lindex $unrooted $n]" |
puts "${n}: [lindex $unrooted $n]" |
||
}</lang> |
}</lang> |
||
=={{header|Wren}}== |
|||
{{trans|Go}} |
|||
{{libheader|Wren-big}} |
|||
{{libheader|Wren-fmt}} |
|||
<lang ecmascript>import "/big" for BigInt |
|||
import "/fmt" for Fmt |
|||
var branches = 4 |
|||
var nMax = 250 |
|||
var rooted = List.filled(nMax + 1, BigInt.zero) |
|||
var unrooted = List.filled(nMax + 1, BigInt.zero) |
|||
var c = List.filled(branches, BigInt.zero) |
|||
var tree |
|||
tree = Fn.new { |br, n, l, sum, cnt| |
|||
var b = br + 1 |
|||
while (b <= branches) { |
|||
sum = sum + n |
|||
if (sum > nMax) return |
|||
if (l*2 >= sum && b >= branches) return |
|||
if (b == br + 1) { |
|||
c[br] = rooted[n] * cnt |
|||
} else { |
|||
var tmp = rooted[n] + BigInt.new(b - br - 1) |
|||
c[br] = c[br] * tmp |
|||
c[br] = c[br] / BigInt.new(b - br) |
|||
} |
|||
if (l*2 < sum) unrooted[sum] = unrooted[sum] + c[br] |
|||
if (b < branches) rooted[sum] = rooted[sum] + c[br] |
|||
var m = n - 1 |
|||
while (m > 0) { |
|||
tree.call(b, m, l, sum, c[br]) |
|||
m = m - 1 |
|||
} |
|||
b = b + 1 |
|||
} |
|||
} |
|||
var bicenter = Fn.new { |s| |
|||
if (s%2 == 0) { |
|||
var tmp = (rooted[(s/2).floor] + BigInt.one) * rooted[(s/2).floor] |
|||
tmp = tmp >> 1 |
|||
unrooted[s] = unrooted[s] + tmp |
|||
} |
|||
} |
|||
rooted[0] = BigInt.one |
|||
rooted[1] = BigInt.one |
|||
unrooted[0] = BigInt.one |
|||
unrooted[1] = BigInt.one |
|||
for (n in 1..nMax) { |
|||
tree.call(0, n, n, 1, BigInt.one) |
|||
bicenter.call(n) |
|||
Fmt.print("$3d: $i", n, unrooted[n]) |
|||
}</lang> |
|||
{{out}} |
|||
Abbreviated. |
|||
<pre> |
|||
1: 1 |
|||
2: 1 |
|||
3: 1 |
|||
4: 2 |
|||
5: 3 |
|||
6: 5 |
|||
7: 9 |
|||
8: 18 |
|||
9: 35 |
|||
10: 75 |
|||
11: 159 |
|||
12: 355 |
|||
13: 802 |
|||
14: 1858 |
|||
15: 4347 |
|||
16: 10359 |
|||
17: 24894 |
|||
18: 60523 |
|||
19: 148284 |
|||
20: 366319 |
|||
21: 910726 |
|||
22: 2278658 |
|||
23: 5731580 |
|||
24: 14490245 |
|||
25: 36797588 |
|||
26: 93839412 |
|||
27: 240215803 |
|||
28: 617105614 |
|||
29: 1590507121 |
|||
30: 4111846763 |
|||
31: 10660307791 |
|||
32: 27711253769 |
|||
33: 72214088660 |
|||
34: 188626236139 |
|||
35: 493782952902 |
|||
... |
|||
249: 5814271898167303040368103945830220447130073898083466852225709084407144308593691069932064987528870826155297 |
|||
250: 16206624309085062837751018464745815688226709117091506494175397665527493805947344857313038875654104100026504 |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |