(33C) (33E) C(y,x), P(y,x) and x!

05072018, 06:36 PM
(This post was last modified: 05072018 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 HPprogrammables, 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  yx must not exceed 69  y can be >69. E.g. the program can calculate C(100,50) and P(100,50). Just try. Code:
Registers used: 0 Total 1 Subtotal 2 Y 3 X 4 YX WORKING: Line 0106 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!)(yx)!] 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 yx (to speed up calculation of y!/x!), or on 0 (to calculate x!) 

05072018, 08:46 PM
(This post was last modified: 05072018 08:47 PM by Dieter.)
Post: #2




RE: (33C) (33E) C(y,x), P(y,x) and x!
(05072018 06:36 PM)Rogier Wrote: The 33E was (is) my first programmable calculator. Limited in capacity compared to most other HPprogrammables, but you can still fit quite a lot in 49 steps + jumps and subroutines. Ah, permutations and combinations – a true classic on programmable calculators without these functions. That's why this topic has been discussed here several times. I'd like to invite you to this thread from last year. These are programs for the 12C, a calculator which is even more limited than the 33E/C. For instance it does not feature subroutines. The first programs posted there required the factorial function. Then an iterative approach similar to yours was implemented, for instance in post#22 (my attempt at this topic). This version does it in 23 steps. There also is a "deluxe version" with some optimizations (e.g. by minimizing the number of loops due to C(n,k) = C(n,n–k). No, there is no special factorial function, but you can get this as well by entering n ENTER 1–n. For instance 5 ENTER –4 returns 120. #) Dieter 

05092018, 06:43 PM
(This post was last modified: 05092018 06:54 PM by Rogier.)
Post: #3




RE: (33C) (33E) C(y,x), P(y,x) and x!
I hadn't found that thread yet. You are of course right; a program many owners of programmable calulators wrote at one time or another. Interesting to see how others approached the problem.
Still: a very useful program and the first posted program for 33C/E as far as I can see. 

05092018, 08:35 PM
Post: #4




RE: (33C) (33E) C(y,x), P(y,x) and x!
(05092018 06:43 PM)Rogier Wrote: I hadn't found that thread yet. You are of course right; a program many owners of programmable calulators wrote at one time or another. Interesting to see how others approached the problem. Yes, that's the reason why I posted the link. And here's another one that is worth reading. All these discussions contain some useful information, e.g. on how to avoid overflow as long as possible, or how to calculate C(n,k) with minimal accuracy loss due to roundoff errors. (05092018 06:43 PM)Rogier Wrote: Still: a very useful program and the first posted program for 33C/E as far as I can see. I think it sure is the first 33C/E combinations/permutations program on this site, and maybe even the first program at all for this calculator. But the linked 12C programs should also run on the 33C/E. ;) Dieter 

05102018, 12:38 PM
(This post was last modified: 05102018 12:39 PM by Rogier.)
Post: #5




RE: (33C) (33E) C(y,x), P(y,x) and x!
Quote:But the linked 12C programs should also run on the 33C/E. Not straight away; the 12C has various functions (e.g. x!), which the 33C/E has not, so you may need some extra lines. I was never very interested in the businessmodels like 38C/E and 12C, but their programming system really is close to the 33C/E. Actually more close even to the 25(C), which doesn't have subroutines either. 

05102018, 01:32 PM
Post: #6




RE: (33C) (33E) C(y,x), P(y,x) and x!
(05102018 12:38 PM)Rogier Wrote:Quote:But the linked 12C programs should also run on the 33C/E. Yes, the first programs in the linked thread require the factorial function. That's why I wrote: (05072018 08:46 PM)Dieter Wrote: The first programs posted there required the factorial function. Then an iterative approach similar to yours was implemented, for instance in post#22 (my attempt at this topic). This version does it in 23 steps. There also is a "deluxe version" with some optimizations (e.g. by minimizing the number of loops due to C(n,k) = C(n,n–k). The two programs in post #22 should also run on the 33C/E. Dieter 

05102018, 05:48 PM
(This post was last modified: 05102018 05:50 PM by Rogier.)
Post: #7




RE: (33C) (33E) C(y,x), P(y,x) and x!
Yes, I know. The similarities are more striking than the differences, and a bit of tinkering is no problem. Besides: if I don't like adapting programs, what am I doing on this forum? As always, part of the fun is in the effort to get a program running. And here the 33C/E (and probably 12C as well) is a real treat. Writing and debugging programs using linenumber adressing without facilities for inserting/deleting lines can be timeconsuming.
I may even go and check out an HP12C emulator some day. 

« Next Oldest  Next Newest »

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