Improved 19C/29C Factorial, Permutation & Combination
|
12-09-2019, 08:59 PM
(This post was last modified: 01-16-2020 03:22 AM by David Hayden.)
Post: #1
|
|||
|
|||
Improved 19C/29C Factorial, Permutation & Combination
Page 112 of the HP 19C/29C Applications Book (available on the museum thumb drive) contains programs to compute factorials, permutations and combinations. The instructions note that the programs don't handle values of n < 2.
In addition, the program for combinations contains a bug. When computing COMB(N,K), if K>N, the program attempts to jump to LBL 8 at step 45 to display "Error," but instead jumps to LBL 8 at step 82 and returns whatever happened to be in register R2. This version handles n >= 0 and fixes the COMB bug. It is also shorter (65 steps vs. 84). The COMB function handles large n and small k by alternately multiplying by one value and dividing by another. This also improves accuracy. It could be improved further using some of the techniques in this excellent thread: https://www.hpmuseum.org/forum/archive/i...-3962.html Edit: See also this version which is much smaller at the expense of handling a smaller range of values in COMB(n,k): https://www.hpmuseum.org/forum/thread-14358.html USAGE: To compute N!: Enter N and press GSB 1. Example: 5 GSB 1 yields 120 To compute PERM(N,K) (the number of ways to permute N items taken K at a time): Enter N, enter K, press GSB 2. Example: 5 ENTER 2 GSB 2 yields 20. To compute COMB(N,K) (the number of ways to combine N items taken K at a time where order doesn't matter): Enter N, enter K, press GSB 3. Example 5 ENTER 2 GSB 3 yields 10. Code: 01. g LBL 1 / 15 13 01 Compute X! |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)