Yahztee for the HP 41 - improve this program!
03-31-2018, 05:44 PM (This post was last modified: 03-31-2018 07:48 PM by Dieter.)
Post: #2
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: Yahztee for the HP 41 - improve this program!
I think you can either have compact code or one that is executing fast. I have not examined the whole program – maybe a complete rewrite is the only way to get substantial improvements – but here are two examples for the sort routine.

Short version (kind of bubble sort):

Code:
LBL 40 14.017   xxx.yyy sorts registers xxx to yyy+1 LBL 41 RCL X 1.001 + RCL IND Y LBL 42 RCL IND Y X<Y? X<> IND T STO IND Z RDN ISG X GTO 42 RDN RDN ISG X GTO 41 RTN

This takes about 4 – 5 seconds for sorting the five numbers in R14...R18.

Edit: if you like watching the RAD annunciator, here is another version that on average also runs faster since it detects whether a register swap occured or not:

Code:
LBL 40 14.017   xxx.yyy sorts registers xxx to yyy+1 LBL 41 ENTER DEG 1.001 + RCL IND Y LBL 42 RCL IND Y X<Y? RAD X<Y? X<> IND T STO IND Z RDN ISG X GTO 42 RDN RDN FC? 43 CLX ISG X GTO 41 DEG RTN

But this version still is a bit slower than yours, and I do not think it saves any bytes.

Finally here is my favourite: it is longer but very fast – essentially it's the same approach as above, but without loops:

Code:
LBL 40 RCL 15 RCL 14 X>Y? X<> 15 STO 14 RCL 16 X<>Y X>Y? X<> 16 STO 14 RCL 17 X<>Y X>Y? X<> 17 STO 14 RCL 18 X<>Y X>Y? X<> 18 STO 14 RCL 16 RCL 15 X>Y? X<> 16 STO 15 RCL 17 X<>Y X>Y? X<> 17 STO 15 RCL 18 X<>Y X>Y? X<> 18 STO 15 RCL 17 RCL 16 X>Y? X<> 17 STO 16 RCL 18 X<>Y X>Y? X<> 18 STO 16 RCL 18 RCL 17 X>Y? X<> 18 STO 17 RTN

This one executes in not much more than a second (!) – in any case.

The part that rolls the dice can be improved as follows.
Input: up to 5-digit number representing the dice to roll, e.g. 12345.

Code:
LBL 71 5 RCL Y 10 ST/ T MOD X#0? X>Y? GTO 72 + 8 + RCL 00 997 * FRC STO 00 6 * 1 + INT STO IND Y LBL 72 R^ INT X#0? GTO 71 XEQ 40 ...

This even saves a label (20). And it also checks whether a die number is zero (invalid).

So far a few first thoughts.

Dieter
 « Next Oldest | Next Newest »

 Messages In This Thread Yahztee for the HP 41 - improve this program! - Gene - 03-30-2018, 07:17 PM RE: Yahztee for the HP 41 - improve this program! - Dieter - 03-31-2018 05:44 PM

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