Combinations and permutations: Difference between revisions
Content added Content deleted
(→{{header|RPL}}: floating point aprox) |
(→{{header|jq}}: add details about gojq) |
||
Line 1,339:
=={{header|jq}}==
and only supports tgamma (true gamma), and thus beyond about 1e308 all accuracy is lost.
<syntaxhighlight lang="jq">def permutation(k): . as $n▼
On the other hand, gojq, the Go implementation, supports
unbounded-precision integer arithmetic,
and the `permutation` and `combination` functions below are
implemented so as to preserve precision.
def permutation(k): . as $n
| reduce range($n-k+1; 1+$n) as $i (1; . * $i);
Line 1,359 ⟶ 1,366:
def big_permutation(k): log_permutation(k) | exp;
def big_combination(k): log_combination(k) | exp;
</syntaxhighlight>
'''Examples using the C implementation''':
12 | permutation(9) #=> 79833600▼
<pre>
</pre>
'''Examples using gojq, the Go implementation'''
<pre>
60 | combinations(30) #=> 118264581564861424
1000 | combination(333) | tostring | "\(.[:40]) ... (\(length) digits in all)"
▲ 170 | big_permutation(133) #=> 5.272846415658284e+263
#=> 5776134553147651669777486323549601722339 ... (275 digits in all)
</pre>
=={{header|Julia}}==
|