(12C) Combination and Permutation
|
08-17-2017, 09:49 PM
(This post was last modified: 08-17-2017 10:05 PM by BartDB.)
Post: #1
|
|||
|
|||
(12C) Combination and Permutation
C(n,r) and P(n,r) for HP-12C.
This should work for all cases where the result is less than 1E100. The C(n,r) routine is based on the identity C(n,r) = C(n,n-r), selecting the minimum value of r and n-r for the calculations. In the loop body, the division and multiplication are done alternately to avoid overflows in cases where the intermediate calculations exceed the dynamic range of the HP-12C. Since doing division can result in non-integer results, the final result is rounded to the nearest integer. The P(n,r) routine is based on the identity P(n,r) = n x (n-1) x (n-2) x ... x (n-r+1). To use the C(n,r) routine, position the program counter at step 0 if it's not there already, key in n, hit enter, key in r and hit R/S. To use the P(n,r) routine, position the program counter at step 25 (GTO 25), key in n, hit enter, key in r and hit R/S. Code: 01 - ; X=n-r Accuracies (wrong didgits are underlined) Combinations
\begin{array}{|l|r|r|}\hline Inputs & HP-12C & Wolfram Alpha \\\hline 15C5 & 3003 & 3003 \\\hline 36C7 & 8347680 & 8347680 \\\hline 90C7 & 747137556\underline{7} & 7471375560 \\\hline 101C6 & 126733992\underline{1} & 1267339920 \\\hline 70C8 & 94403509\underline{38} & 9440350920 \\\hline 425C23 & 5.9872995\underline{10}E37 & 5.987299532821716... E37 \\\hline 200C55 & 7.7183408\underline{23}E49 & 7.718340811430957... E49 \\\hline 335C167 & 3.044358\underline{801}E99 & 3.044358793146979... E99 \\\hline \end{array} Permutations
\begin{array}{|l|r|r|}\hline 25P7 & 2422728000 & 2422728000 \\\hline 99P5 & 8582777280 & 8582777280 \\\hline 100P45 & 7.35060259\underline{4}E84 & 7.350602595423500... E84 \\\hline 5000P27 & 6.94462245\underline{9}E99 & 6.944622452543926... E99 \\\hline \end{array} |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(12C) Combination and Permutation - BartDB - 08-17-2017 09:49 PM
RE: (12C) Combination and Permutation - Gamo - 08-18-2017, 08:28 AM
RE: (12C) Combination and Permutation - pier4r - 08-18-2017, 08:55 AM
RE: (12C) Combination and Permutation - BartDB - 08-18-2017, 04:58 PM
RE: (12C) Combination and Permutation - pier4r - 08-18-2017, 05:12 PM
RE: (12C) Combination and Permutation - Gamo - 08-18-2017, 11:36 AM
RE: (12C) Combination and Permutation - pier4r - 08-18-2017, 12:50 PM
RE: (12C) Combination and Permutation - Joe Horn - 08-18-2017, 02:54 PM
RE: (12C) Combination and Permutation - pier4r - 08-18-2017, 03:18 PM
RE: (12C) Combination and Permutation - Dieter - 08-19-2017, 05:26 PM
RE: (12C) Combination and Permutation - Gamo - 03-15-2020, 11:37 AM
|
User(s) browsing this thread: 10 Guest(s)