Post Reply 
(33C) (33E) C(y,x), P(y,x) and x!
05-07-2018, 06:36 PM (This post was last modified: 05-07-2018 06:44 PM by Rogier.)
Post: #1
(33C) (33E) C(y,x), P(y,x) and x!
The 33E was (is) my first programmable calculator. Limited in capacity compared to most other HP-programmables, but you can still fit quite a lot in 49 steps + jumps and subroutines.
HP supplies solutions programs for C(y,x) and P(y,x), but these are bulky. This program calculates C(y,x), P(y,x) and x! in 43 lines.

USE:
y ENTER x R/S > C(y,x) X<=>Y P(y,x)
0 ENTER x R/S > x!

NOTE:
- x and y must be 0 or positive integers
- x<y
- y-x must not exceed 69
- y can be >69. E.g. the program can calculate C(100,50) and P(100,50). Just try.

Code:

01 X=0?
02 GTO 38
03 Sto 3
04 X <=> Y
05 X=0?
06 GTO 41
07 Sto 2
08 X<=>Y
09 -
10 Sto 4
11 Rcl 2
12 GSB 27
13 Sto 0
14 0
15 Sto 4
16 Rcl 4
17 GSB 27
18 Sto / 0
19 Rcl 2
20 Rcl 4
21 -
22 GSB 27
23 Rcl 0
24 *
25 Rcl 0
26 GTO 00
27 Sto 1
28 1
29 -
30 Rcl 3
31 X=Y?
32 GTO 36
33 X<=>Y
34 Sto * 1
35 GTO 28
36 Rcl 1
37 Rtn
38 1
39 ENTER
40 GTO 00
41 Sto 3
42 X<=>Y
43 GSB 27

Registers used:
0 Total
1 Subtotal
2 Y
3 X
4 Y-X

WORKING:
Line 01-06 sort out the special cases;
- (y,0) [> GTO 38, display 1 and stop] or
- (0,x) [GTO 41, call the x! routine (27) and stop. This may seem unnecessarily complicated but the 33C/E interprets Rtn without preceding GSB as R/S, not as GTO 00 like I want.]
After this the program calculates C(y,x) = y!/[(x!)(y-x)!] then it multiplies C(y,x) by x! to get P(y,x). (I could swap calculation of P(y,x) and C(y,x), but then I can't use y!/x! And that is what enables the program tot function with y>69).
Lines 27 ... 37 form the main loop. This loop is set to terminate on y-x (to speed up calculation of y!/x!), or on 0 (to calculate x!)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(33C) (33E) C(y,x), P(y,x) and x! - Rogier - 05-07-2018 06:36 PM



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