Paraffins: Difference between revisions

Content added Content deleted
m (aligned formulas, used colored window, increased whitespace.)
(Updated to work with Nim 1.4: added missing parameter types, replaced ".. <" with "..<". Also added "libheader" for "bigints" module.)
Line 1,603: Line 1,603:
=={{header|Nim}}==
=={{header|Nim}}==
{{trans|C}}
{{trans|C}}
{{libheader|bigints}}
<lang nim>import bigints
<lang nim>import bigints


Line 1,616: Line 1,617:
unrooted[i] = 0.initBigInt
unrooted[i] = 0.initBigInt


proc choose(m, k): BigInt =
proc choose(m; BigInt; k: int32): BigInt =
result = m
result = m
if k == 1: return
if k == 1: return
for i in 1 .. < k:
for i in 1 ..< k:
result = result * (m + i) div (i + 1)
result = result * (m + i) div (i + 1)


proc tree(br, n, l, sum: int32, cnt: BigInt) =
proc tree(br, n, l, sum: int32; cnt: BigInt) =
var s: int32 = 0
var s: int32 = 0
for b in br + 1 .. nBranches:
for b in br + 1 .. nBranches:
Line 1,636: Line 1,637:
tree b, m, l, s, c
tree b, m, l, s, c


proc bicenter(s) =
proc bicenter(s: int32) =
if (s and 1) == 0:
if (s and 1) == 0:
unrooted[s] += rooted[s div 2] * (rooted[s div 2] + 1) div 2
unrooted[s] += rooted[s div 2] * (rooted[s div 2] + 1) div 2
Line 1,644: Line 1,645:
n.bicenter
n.bicenter
echo n, ": ", unrooted[n]</lang>
echo n, ": ", unrooted[n]</lang>

Output:
{{out}}
<pre>1: 1
<pre>1: 1
2: 1
2: 1