HP-41 Challenge! « Next Oldest | Next Newest »

 ▼ Jeff Member Posts: 245 Threads: 97 Joined: Jun 2007 04-24-2003, 08:14 PM 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? ▼ Johnny Billquist Junior Member Posts: 49 Threads: 2 Joined: Jan 1970 04-25-2003, 08:42 AM 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 That's my suggestion anyway. ▼ Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 04-25-2003, 11:27 AM Hello, John; may I? I just arrengend (formatted) your solution. ```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``` 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 - 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``` I hope you don't be mad with me... This is just another way to use your solution. Best regards. Luiz C. Vieira - Brazil ▼ Jean-Marc Baillard Junior Member Posts: 2 Threads: 0 Joined: Jan 1970 04-25-2003, 04:57 PM Hi, everyone! here is a solution to this challenge: 1 Xy for interchange x and y) and assuming the value to be tested is already in x: 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 (resume whatever you were doing here) ▼ Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 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 ▼ Dave Shaffer (Arizona) Posting Freak Posts: 776 Threads: 25 Joined: Jun 2007 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? ▼ Vieira, Luiz C. (Brazil) Posting Freak Posts: 4,027 Threads: 172 Joined: Aug 2005 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 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``` (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 ▼ Jeff Member Posts: 245 Threads: 97 Joined: Jun 2007 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 Xy 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 ▼ Jeff Member Posts: 245 Threads: 97 Joined: Jun 2007 04-26-2003, 09:11 PM Thanks again to all that posted regarding this thread. Here are the results for the challenge. Johnny Billquist 64 Bytes/.64 seconds=100 BT Jean-Marc Baillard 53 Bytes/.50 seconds=106 BT Dave Shaffer 54 Bytes/1.04 seconds=51.92 BT Jeff Davis 53 Bytes/.71 seconds=74.67 BT Congratulations Jean-Marc Baillard! These byte counts include an .END and a LBL. Thanks to all. If there are further thoughts to make this sequence faster or shorter please let us know. Best Regards, Jeff Johnny Billquist Junior Member Posts: 49 Threads: 2 Joined: Jan 1970 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. I don't like it just because I want to keep stack usage to a minimum, but apart from that it's efficient. Jeff Member Posts: 245 Threads: 97 Joined: Jun 2007 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. Thanks to all, Jeff Johnny Billquist Junior Member Posts: 49 Threads: 2 Joined: Jan 1970 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.

 Possibly Related Threads... Thread Author Replies Views Last Post HP-41(CL): The easiest way to transfer FOCAL programs from a Linux PC to the HP-41 Geir Isene 13 3,525 12-05-2013, 02:40 AM Last Post: Hans Brueggemann 41-MCODE: a weekend challenge Ángel Martin 3 1,052 03-19-2012, 06:49 AM Last Post: Mike (Stgt) HP-15C mini-challenge (Project Euler - problem #1) Gerson W. Barbosa 14 2,683 05-08-2011, 11:08 AM Last Post: Marcus von Cube, Germany HP-12C mini-challenge - Heegner numbers Gerson W. Barbosa 19 3,180 03-26-2011, 02:41 PM Last Post: Gerson W. Barbosa HP-12C mini-challenge (e^pi) Gerson W. Barbosa 30 4,387 11-06-2009, 07:03 AM Last Post: Gerson W. Barbosa Challenge: Open-ended Dice on the HP-41 Geir Isene 2 842 09-06-2009, 03:38 PM Last Post: hugh steers HP-15C Mini-Challenge: Magic squares ! Valentin Albillo 12 2,135 06-21-2009, 08:53 AM Last Post: Bruno Férard More Forth-41 and HHC2008 Challenge Fun Egan Ford 0 462 10-16-2008, 07:21 PM Last Post: Egan Ford HP-41CX (or 41C/CV + Time module) challenge Geir Isene 3 1,034 12-09-2007, 04:18 PM Last Post: Vieira, Luiz C. (Brazil) RE: 35s sorting routine challenge - Gene's Challenge Miguel Toro 4 1,115 08-01-2007, 08:36 AM Last Post: Miguel Toro

Forum Jump: