Post Reply 
HP 12C Permutation and Combination
08-16-2017, 09:12 PM
Post: #2
RE: HP 12C Permutation and Combination
(08-15-2017 04:54 AM)Gamo Wrote:  To use it just start at GTO 00 for Permutation and GTO 10 for Combination. Very easy to remember to start at GTO 10 for Combination.

Here is a version that implements an idea already posted in an earlier thread: have a common entry point (ideally line 00) and use a code number for different functions. Since C(n,k) simply is P(n,k) / k! this can be done in one common routine:

Code:
01 STO 0
02 X=0?
03 e^x
04 STO/0
05 ENTER
06 -
07 +
08 STO*0
09 -
10 n!
11 x<>y
12 n!
13 x<>y
14 /
15 RCL 0
16 n!
17 /
18 GTO 00

Usage:
n [ENTER] k [ENTER] 0 [R/S] => P(n,k)
n [ENTER] k [ENTER] 1 [R/S] => C(n,k)

Instead of 1 any other value ≠ 0 may be used.

Example:
25 [ENTER] 6 [ENTER] 0 [R/S] => 127512000
25 [ENTER] 6 [ENTER] 1 [R/S] => 177000

The first four lines store either 0 or 1 in R0, line 08 turns R0 into 0 or k, and after P(n,k) has been calculated it is divided by R0! (i.e. by 1 or by k!) to obtain the final result. The calculation of P(n,k) is done on the stack and requires no additional register.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 12C Permutation and Combination - Gamo - 08-15-2017, 04:54 AM
RE: HP 12C Permutation and Combination - Dieter - 08-16-2017 09:12 PM



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