(12C) Permutation & Combination revisit
|
07-25-2024, 08:36 AM
Post: #1
|
|||
|
|||
(12C) Permutation & Combination revisit
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 |
|||
07-28-2024, 10:57 AM
Post: #2
|
|||
|
|||
RE: (12C) Permutation & Combination revisit
The same, just a little shorter:
Code: 01- 34 : x<>y Now you have to GTO 11 to calculate Combination nCr. |
|||
07-28-2024, 04:29 PM
(This post was last modified: 08-07-2024 05:38 PM by C.Ret.)
Post: #3
|
|||
|
|||
RE: (12C) Permutation & Combination revisit
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. |
|||
07-28-2024, 05:57 PM
Post: #4
|
|||
|
|||
RE: (12C) Permutation & Combination revisit
Excellent code. Most efficient. Thanks!
|
|||
08-04-2024, 03:09 PM
(This post was last modified: 08-04-2024 04:08 PM by AnnoyedOne.)
Post: #5
|
|||
|
|||
RE: (12C) Permutation & Combination revisit
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. HP-15C (2234A02xxx), HP-16C (2403A02xxx), HP-15C CE (9CJ323-03xxx), HP-20S (2844A16xxx), HP-12C+ (9CJ251) |
|||
08-07-2024, 05:32 PM
(This post was last modified: 08-07-2024 05:39 PM by C.Ret.)
Post: #6
|
|||
|
|||
RE: (12C) Permutation & Combination revisit
(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? |
|||
08-07-2024, 05:49 PM
Post: #7
|
|||
|
|||
RE: (12C) Permutation & Combination revisit
(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. HP-15C (2234A02xxx), HP-16C (2403A02xxx), HP-15C CE (9CJ323-03xxx), HP-20S (2844A16xxx), HP-12C+ (9CJ251) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)