Post Reply 
(12C) Permutation & Combination revisit
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
02-      33  R↓
03-   43  3  n!
04-   43 36  LSTx
05-    45 0  RCL 0
06-      30   -
07-   43  3  n!
08-      10   ÷
09-      31  R/S
10-    45 0  RCL 0
11-43,33 07  GTO 07

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.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (12C) Permutation & Combination revisit - C.Ret - 07-28-2024 04:29 PM



User(s) browsing this thread: 2 Guest(s)