If you have a number in X.
You need to test this number against the values:
1,2.5,3.125
X<=Y? or similar test.
You need to perform (4) Different actions based on the results of the tests.
If X<=1.0 then add .1
If X<=2.5 then Multiply by 1.1
If X<=3.125 then add .2
Else Multiply by 1.08
The HP-48GX has the CASE function which performs this very well. What is the best solution for the HP-41?
I have tried using the GTO statements and LBL statements.
I have tried using flags to direct the program execution but I think that my attemps, Although they work,are not quite good.
What is the best Byte/Time ratio that can be obtained?
HP-41 Challenge!
|
|
« Next Oldest | Next Newest »
|
▼
04-24-2003, 08:14 PM
▼
04-25-2003, 08:42 AM
1
▼
04-25-2003, 11:27 AM
Hello, John; may I? I just arrengend (formatted) your solution. 1
here the original program continues, right? May I use your suggestion and make it work like a subroutine call? This way it would look like: 1 I hope you don't be mad with me... This is just another way to use your solution. Best regards. Luiz C. Vieira - Brazil
▼
04-25-2003, 04:57 PM
Hi, everyone! here is a solution to this challenge:
1
Best regards, ▼
04-25-2003, 06:38 PM
Try turning it around - check from the high side first. In Luiz'z notation (and using x<>y for interchange x and y) and assuming the value to be tested is already in x:
3.125 ▼
04-25-2003, 07:58 PM
Hello, Dave; yours is a very elegant solution. If I am not wrong, it seems to me Jeff's original verrsion resembles yours. At least I remeber seeing this x<>y comparison "structure" a few months ago. Is it correct, Jeff? Best regards. (It seems a lot of us still program -or remember how to- under RPN with style...) Luiz C. Vieira - Brazil
▼
04-25-2003, 11:46 PM
Luiz, Thank you for your kind words. I sort of messed up my presentation - I intended to have line breaks at each step, as you have showed us how to do! (It looked so good before I sent it!) I suspect that with a little more attention paid to the x and y variables on the stack and the order of the comparison (greater than or less than) that you could save even a few more steps. To Jeff: did you really have a problem where this particular order of comparison and subsequent arithmetic was needed? ▼
04-26-2003, 12:28 AM
Hello, Dave; some souls are gone, others are about to come, but kindness and politeness are timeless, isn't it? That's what makes this Forum rule: people in here are amazingly kind and polite. Thank you too, Dave; my pleasure. About the listing: if you wnat something to be shown the way you typed it in, start it with a [pre] and finish it with a [/pre]. Both [pre] and [/pre] will be invisible; to show them it's necessary to use the \\[ and \\] trick. Look at your own listing below: 3.125(resume whatever you were doing here) Was it what you wnated? the [pre] and [/pre] are Dave Hicks' gifts for us, amongst others... PLease, have a look here and you'll understand better. Best regards. Luiz C. Vieira - Brazil ▼
04-26-2003, 08:46 AM
Thanks to all who posted responses on this thread. I have taken the liberty of compiling all the responses into a list and will be trying each one out for byte/time. I have been working on this routine for a while and thought that there surely was a better method to complete what I needed to have done. This is the reason that I posted this challenge. Below is the list. I will post the byte counts and input/outputs sometime this weekend. Again thanks to all. E X<>Y X<=Y? GTO 01 2.5 X<>Y X<=Y? GTO 02 3.125 X<>Y X<=Y? GTO 03 1.08 * RTN LBL 01 .1 + RTN LBL 01 1.1 + RTN LBL 03 .2 + RTN "Jeff" my original program. 1 - X<=0? GTO 00 1.5 - X<=0? GTO 01 0.625 - X<=0? GTO 02 3.125 + 1.08 * GTO 03 LBL 00 2 + GTO 03 LBL 01 2.5 + 1.1 * GTO 03 LBL 02 3.325 + LBL 03 1 - X<=0? GTO 00 1.5 - X<=0? GTO 01 0.625 - X<=0? GTO 02 3.125 + 1.08 * GTO 03 LBL 00 2 + GTO 03 LBL 01 2.5 + 1.1 * GTO 03 LBL 02 3.325 + LBL 03 1 - X<=0? GTO 00 1.5 - X<=0? GTO 01 0.625 - X<=0? GTO 02 3.125 + 1.08 * RTN LBL 00 2 + RTN LBL 01 2.5 + 1.1 * RTN LBL 02 3.325 + RTN 1 X<Y? GTO 01 + RTN LBL 01 CLX 2.5 X<Y? GTO 01 CLX 1.1 * RTN LBL 01 CLX 3.125 X<Y? GTO 01 CLX .2 + RTN LBL 01 CLX 1.08 * RTN 3.125 x<>y x>y? GTO 00 2.0 x<>y x>y? GTO 01 1.0 x<>y x>y GTO 02 0.1 + GTO 03 LBL 00 1.08 * GTO 03 LBL 01 0.2 + GTO 03 LBL 02 1.1 * LBL 03 3.125 x<>y x>y? GTO 00 2.0 x<>y x>y? GTO 01 1.0 x<>y x>y GTO 02 0.1 + GTO 03 LBL 00 1.08 * GTO 03 LBL 01 0.2 + GTO 03 LBL 02 1.1 * LBL 03 ▼
04-26-2003, 09:11 PM
Thanks again to all that posted regarding this thread. Here are the results for the challenge.
04-28-2003, 06:49 AM
This solution is a bit shorter than mine, but offers the stack for it. It depends on what you need.
04-27-2003, 02:25 PM
This particular routine, is being used to calculate a safe distance between centers that will be used in a subsequent calculation. The subsequent calculation will determine how many cavities can fit into a mold using a square or round pattern. Similar to wire packings.
04-28-2003, 06:50 AM
Thanks. I didn't realize it would become so messed up. I wrote it the way you formatted it for me. Much obliged. I'll try to remember the \[pre\] next time, now that I know. And yes, it might be prettier to have as a subroutine. |