(12C) Permutation & Combination revisit - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (12C) Permutation & Combination revisit (/thread-22079.html) |
(12C) Permutation & Combination revisit - Gamo - 07-25-2024 08:36 AM This program calculate the Permutation nPr and Combination nCr using the HP-12C with this program it can be use to do arithmetic calculation. ----------------------------------------------------------------------- Usage: For Permutaion make sure program is at the beginning [f] PRGM for Combination start program at line 16 [g] GTO 16 nPr is Permutation input n [ENTER] r [R/S] display answer nCr is Combination input n [ENTER] r [R/S] display answer Both for n > r ------------------------------------------------------------ Example: FIX 0 11P6 - 8P5 = ? [f] PRGM 11 [ENTER] 6 [R/S] display 332640 8 [ENTER] 5 [R/S] display 6720 [-] display answer 325920 ----------------------------------------------------------------- 12C5 - 9P7 = ? [g] GTO 16 12 [ENTER] 5 [R/S] display 792 [f] PRGM 9 [ENTER] 7 [R/S] display 181440 [-] display answer -180648 ------------------------------------------------------------------ 8P3 + 6C3 - 5P3 = ? [f] PRGM 8 [ENTER] 3 [R/S] display 336 [g] GTO 16 6 [ENTER] 3 [R/S] display 20 [+] display 356 [f] PRGM 5 [ENTER] 3 [R/S] display 60 [-] display answer 296 --------------------------------------------------------- Program: Quote:01 X<>Y Gamo 7/2024 RE: (12C) Permutation & Combination revisit - Thomas Klemm - 07-28-2024 10:57 AM The same, just a little shorter: Code: 01- 34 : x<>y Now you have to GTO 11 to calculate Combination nCr. RE: (12C) Permutation & Combination revisit - C.Ret - 07-28-2024 04:29 PM Dear friends, These codes are interesting, but they are actually two codes in one. If we are allowed to use a memory register and without changing the way we enter \(n\) and \(k\) in the stack, it is possible to make a shorter code. Indeed \( P(n,k) = \frac{n!}{(n-k)!}\) and \(C(n,k)=\frac{n!}{(n-k)! \cdot k!}\) thus \(C(n,k)=\frac{P(n,k)}{k!}\). The idea is that instead of typing a GTO xx to start the calculation of the combinations from scratch, it is enough to press R/S when the number of Permutations \(P(n,k)\) is displayed to continue and terminate the computation of the Combinaisons \(C(n,k)\). So I propose the following code: Code: 01- 44 0 STO 0 P.S.: It is possible to save an instruction by changing the way \(n\) and \(k\) are entered in the stack (but this make a lot of R/S - this version is the easier to use. Usage: Permutations: Restart from start : [ f ] [ Prgm ] Enter \(n\) and \(k\) : n [ENTER] k Press [R/S] to run the code and get the # of permutations \(P(n,k)\) Combinaisons: Restart from start : [ f ] [ Prgm ] Enter \(n\) and \(k\) : n [ENTER] k Press [R/S] to run the code and press [R/S] a second time when Permutations are displayed to get the # of Combinaisons \(C(n,k)\). Example: 8P3 + 6C3 - 5P3 = ? 8 [ f ][ PRGM ] 3 [R/S] display 336 6 [ f ][ PRGM ] 3 [R/S] display 120 [R/S] display 20 [+] display 356 5 [ f ][ PRGM ] 3 [R/S] display 60 [-] display answer 296. EDIT: 24-AOUT-07 Typo in key-codes of RCL 0. Mnemonic Rdn replace by R↓ see folling posts. RE: (12C) Permutation & Combination revisit - Matt Agajanian - 07-28-2024 05:57 PM Excellent code. Most efficient. Thanks! RE: (12C) Permutation & Combination revisit - AnnoyedOne - 08-04-2024 03:09 PM IMHO "Rdn" probably should be "ROLL". However the keycode (33) is correct. The "RCL 0" keycodes should be "45 0" not "44 0". The code works in my HP HP-12C PC (v1.2 11/29/2012) & Android (v1.6.5 5/26/2015) "virtual calculators". I don't have a HP-12C. RE: (12C) Permutation & Combination revisit - C.Ret - 08-07-2024 05:32 PM (08-04-2024 03:09 PM)AnnoyedOne Wrote: IMHO "Rdn" probably should be "ROLL". However the keycode (33) is correct. Thanks you to point out this two inaccuracies. I correct the key-codes of the RCL operations in my post. Rdn stand for Roll-Down, I may perhaps have use R↓ instead? RE: (12C) Permutation & Combination revisit - AnnoyedOne - 08-07-2024 05:49 PM (08-07-2024 05:32 PM)C.Ret Wrote: I may perhaps have use R↓ instead?No worries. I didn't know that the forum supported that (hence ROLL). I know my PC text editors don't. |