The Museum of HP Calculators


Combination for the HP-25

This program is Copyright © 1975 by Hewlett-Packard and is used here by permission. This program was originally published in "HP-25 Applications Programs".

This program is supplied without representation or warranty of any kind. Hewlett-Packard Company and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Overview

A combination is a selection of one or more of a set of distinct objects without regard to order. The number of possible combinations, each containing n objects, that can be formed from a collection of m distinct objects is given by

                     m!          m(m-1) ... (m-n+1)
          mCn = ------------ = ----------------------
                  (m-n)!n!        1 × 2 × ... × n

where m, n are integers and 0 ≤ n ≤ m.

This program computes mCn using the following algorithm:

1. If n ≤ m-n

                  m-n+1       m-n+2            m
          mCn = --------- × --------- × ... × ---
                    1           2              n

2. If n > m - n, program computes mCm-n.

Notes:

  1. mCn, which is also called the binomial coefficient, can be denoted by Cmn, C(m,n), or (mn)
  2. mCn = mCm-n
  3. mC0 = mCm = 1
  4. mC1 = mCm-1 = m

Instructions

Step Instructions Input Data/Units Keys Output Data/Units
1 Enter program      
2 Enter m and n and m ENTER↑  
3 Compute combinations n f PRGM R/S mCn
4 For new case, go to step 2      

Examples

  1. 73C4 = 1088430.00
  2. 43C3 = 12341.00

The Program

LINE    CODE    KEYS
 00  
 01        41   -
 02     14 73   f LASTx
 03     14 41   f x<y
 04        21   x⇔y
 05     23 00   STO 0
 06        01   1
 07     23 01   STO 1
 08        51   +
 09     23 02   STO 2
 10        22   R↓
 11     15 71   g x=0
 12     13 30   GTO 30
 13        01   1
 14     24 01   RCL 1
 15        51   +
 16     23 01   STO 1
 17        21   x⇔y
 18     14 51   f x≥y
 19     13 22   GTO 22
 20     24 02   RCL 2
 21     13 00   GTO 00
 22        21   x⇔y
 23     24 00   RCL 0
 24        51   +
 25     24 01   RCL 1
 26        71   ÷
 27  23 61 02   STO x 2
 28        22   R↓
 29     13 13   GTO 13
 30        01   1
 31     13 00   GTO 00

Register Use

R0  max(n, m-n)
R1  used
R2  used

Go back to the software library
Go back to the main exhibit hall