Combinations and permutations: Difference between revisions
Content deleted Content added
jq |
Added Bracmat example |
||
Line 209: | Line 209: | ||
(1000 C 998) = 499500.0, (1000 C 969) = 76023224077705100000000000000000000000000000000000000000000.0 |
(1000 C 998) = 499500.0, (1000 C 969) = 76023224077705100000000000000000000000000000000000000000000.0 |
||
</pre> |
</pre> |
||
=={{header|Bracmat}}== |
|||
Bracmat cannot handle floating point numbers. Instead, this solution shows the first 50 digits and a count of the digits that are not shown. |
|||
<lang Bracmat>( ( C |
|||
= n k coef |
|||
. !arg:(?n,?k) |
|||
& (!n+-1*!k:<!k:?k|) |
|||
& 1:?coef |
|||
& whl |
|||
' ( !k:>0 |
|||
& !coef*!n*!k^-1:?coef |
|||
& !k+-1:?k |
|||
& !n+-1:?n |
|||
) |
|||
& !coef |
|||
) |
|||
& ( P |
|||
= n k result |
|||
. !arg:(?n,?k) |
|||
& !n+-1*!k:?k |
|||
& 1:?result |
|||
& whl |
|||
' ( !n:>!k |
|||
& !n*!result:?result |
|||
& !n+-1:?n |
|||
) |
|||
& !result |
|||
) |
|||
& 0:?i |
|||
& whl |
|||
' ( 1+!i:~>12:?i |
|||
& div$(!i.3):?k |
|||
& out$(!i P !k "=" P$(!i,!k)) |
|||
) |
|||
& 0:?i |
|||
& whl |
|||
' ( 10+!i:~>60:?i |
|||
& div$(!i.3):?k |
|||
& out$(!i C !k "=" C$(!i,!k)) |
|||
) |
|||
& ( displayBig |
|||
= |
|||
. @(!arg:?show [50 ? [?length) |
|||
& !show "... (" !length+-50 " more digits)" |
|||
| !arg |
|||
) |
|||
& 5 50 500 1000 5000 15000:?is |
|||
& whl |
|||
' ( !is:%?i ?is |
|||
& div$(!i.3):?k |
|||
& out$(str$(!i " P " !k " = " displayBig$(P$(!i,!k)))) |
|||
) |
|||
& 0:?i |
|||
& whl |
|||
' ( 100+!i:~>1000:?i |
|||
& div$(!i.3):?k |
|||
& out$(str$(!i " C " !k " = " displayBig$(C$(!i,!k)))) |
|||
) |
|||
);</lang> |
|||
Output: |
|||
<pre>1 P 0 = 1 |
|||
2 P 0 = 1 |
|||
3 P 1 = 3 |
|||
4 P 1 = 4 |
|||
5 P 1 = 5 |
|||
6 P 2 = 30 |
|||
7 P 2 = 42 |
|||
8 P 2 = 56 |
|||
9 P 3 = 504 |
|||
10 P 3 = 720 |
|||
11 P 3 = 990 |
|||
12 P 4 = 11880 |
|||
10 C 3 = 120 |
|||
20 C 6 = 38760 |
|||
30 C 10 = 30045015 |
|||
40 C 13 = 12033222880 |
|||
50 C 16 = 4923689695575 |
|||
60 C 20 = 4191844505805495 |
|||
5 P 1 = 5 |
|||
50 P 16 = 103017324974226408345600000 |
|||
500 P 166 = 35348749217429427876093618266017623068440028791060... (385 more digits) |
|||
1000 P 333 = 59693262885034150890397017659007842809981894765670... (922 more digits) |
|||
5000 P 1666 = 68567457572556742754845369402488960622341567102448... (5976 more digits) |
|||
15000 P 5000 = 96498539887274939220148588059312959807922816886808... (20420 more digits) |
|||
100 C 33 = 294692427022540894366527900 |
|||
200 C 66 = 72697525451692783415270666511927389767550269141935... (4 more digits) |
|||
300 C 100 = 41582514632585647447833835263264055802804660057436... (32 more digits) |
|||
400 C 133 = 12579486841821087021333484756519650044917494358375... (60 more digits) |
|||
500 C 166 = 39260283861944227552204083450723314281973490135301... (87 more digits) |
|||
600 C 200 = 25060177832214028050056167705132288352025510250879... (115 more digits) |
|||
700 C 233 = 81032035633395999047404536440311382329449203119421... (142 more digits) |
|||
800 C 266 = 26456233626836270342888292995561242550915240450150... (170 more digits) |
|||
900 C 300 = 17433563732964466429607307650857183476303419689548... (198 more digits) |
|||
1000 C 333 = 57761345531476516697774863235496017223394580195002... (225 more digits)</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |