Combinations and permutations: Difference between revisions
→{{header|Bracmat}}: Added floating point implementations of C and P
(→{{header|jq}}: add details about gojq) |
(→{{header|Bracmat}}: Added floating point implementations of C and P) |
||
Line 322:
=={{header|Bracmat}}==
<syntaxhighlight lang="bracmat">
= n k coef
. !arg:(?n,?k)
Line 336:
& !coef
)
& ( compileBinomialFunctionThatDoesFloatingPointCalculations
=
. new
$ ( UFP
,
' ( (s.n) (s.k)
. "**************************************************************
*** Notice the difference between the following four lines ***
*** of code and the much shorter (!n+-1*!k:<!k:?k|) in ***
*** function C above. UFP grammar is simpler than usual ***
*** Bracmat grammar. UFP code is therefore less terse. ***
**************************************************************"
& !n+-1*!k:?n-k
& ( !n-k:<!k&!n-k:?k
|
)
& 1:?coef
& whl
' ( !k:>0
& !coef*!n*!k^-1:?coef
& !k+-1:?k
& !n+-1:?n
)
& !coef
)
)
)
& compileBinomialFunctionThatDoesFloatingPointCalculations$
: ?binom
& ( P
= n k result
Line 348 ⟶ 377:
& !result
)
& ( compilePermutationFunctionThatDoesFloatingPointCalculations
=
. new
$ ( UFP
,
' ( (s.n) (s.k)
. !n+-1*!k:?k
& 1:?result
& whl
' ( !n:>!k
& !n*!result:?result
& !n+-1:?n
)
& !result
)
)
)
& compilePermutationFunctionThatDoesFloatingPointCalculations$
: ?permu
& 0:?i
& whl
Line 358 ⟶ 406:
' ( 10+!i:~>60:?i
& div$(!i.3):?k
& out$(!i
& out$(!i Cf !k "=" (binom..go)$(!i,!k))
)
& ( displayBig
Line 370 ⟶ 419:
' ( !is:%?i ?is
& div$(!i.3):?k
& out
$ ( str
$ (!i " Pn " !k " = " displayBig$(P$(!i,!k)))
)
& out
$ ( str
$ (!i " Pf " !k " = " (permu..go)$(!i,!k))
)
)
& 0:?i
Line 376 ⟶ 432:
' ( 100+!i:~>1000:?i
& div$(!i.3):?k
& out
$ ( str
$ (!i " Cn " !k " = " displayBig$(C$(!i,!k)))
)
& out
$ ( str
$ (!i " Cf " !k " = " (binom..go)$(!i,!k))
)
)
Output:
<pre>1 P 0 = 1
Line 392 ⟶ 455:
11 P 3 = 990
12 P 4 = 11880
10
10 Cf 3 = 1.1999999999999999E+02
20 Cf 6 = 3.8759999999999993E+04
30 Cf 10 = 3.0045014999999989E+07
40 Cf 13 = 1.2033222880000000E+10
50 Cn 16 = 4923689695575
50 Cf 16 = 4.9236896955750000E+12
60 Cn 20 = 4191844505805495
60 Cf 20 = 4.1918445058054930E+15
5 Pn 1 = 5
5 Pf 1 = 5.0000000000000000E+00
50 Pn 16 = 103017324974226408345600000
50 Pf 16 = 1.0301732497422640E+26
500
500 Pf 166 = INF
1000 Pf 333 = INF
5000 Pf 1666 = INF
15000 Pn 5000 = 96498539887274939220148588059312959807922816886808... (20420 more digits)
15000 Pf 5000 = INF
100 Cn 33 = 294692427022540894366527900
100 Cf 33 = 2.9469242702254079E+26
200 Cn 66 = 72697525451692783415270666511927389767550269141935... (4 more digits)
200 Cf 66 = 7.2697525451692816E+53
300 Cn 100 = 41582514632585647447833835263264055802804660057436... (32 more digits)
300 Cf 100 = 4.1582514632585569E+81
400 Cn 133 = 12579486841821087021333484756519650044917494358375... (60 more digits)
400 Cf 133 = 1.2579486841821091E+109
500 Cn 166 = 39260283861944227552204083450723314281973490135301... (87 more digits)
500 Cf 166 = 3.9260283861944195E+136
600 Cn 200 = 25060177832214028050056167705132288352025510250879... (115 more digits)
600 Cf 200 = 2.5060177832213946E+164
700 Cn 233 = 81032035633395999047404536440311382329449203119421... (142 more digits)
700 Cf 233 = 8.1032035633395859E+191
800 Cn 266 = 26456233626836270342888292995561242550915240450150... (170 more digits)
800 Cf 266 = 2.6456233626836295E+219
900 Cn 300 = 17433563732964466429607307650857183476303419689548... (198 more digits)
900 Cf 300 = 1.7433563732964451E+247
1000 Cn 333 = 57761345531476516697774863235496017223394580195002... (225 more digits)
1000 Cf 333 = 5.7761345531476355E+274
{!} all done</pre>
=={{header|C}}==
|