Help Squeezing some HP67/97 code  Printable Version + HP Forums (https://archived.hpcalc.org/museumforum) + Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum1.html) + Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum2.html) + Thread: Help Squeezing some HP67/97 code (/thread82707.html) 
Help Squeezing some HP67/97 code  Howard Owen  11222005 I'm trying to shoehorn YATZ into the HP67/97 I'm doing fine with labels, but I'm running out of program lines. The exercise has convinced me that I can finish the port to the 33S, however, so I've shelved the 97 version for now and am working on the 33S. I'm looking for opportunities to shrink the code size while I do that, however. Below is an algorithm I developed for extracting the nth digit (counting left to right) in a number. It is rather lengthy. Can anyone see a way to shrink it? Is there another approach to this problem anyone is aware of that might be shorter?
L0001 *LBL L ! Extract the Yth digit (counting left to right) from the number in X
Regards,
Edited: 22 Nov 2005, 1:00 p.m.
Re: Help Squeezing some HP67/97 code  Vieira, Luiz C. (Brazil)  11222005 Hi, Howard; Please, would you try this one? *LBL L !I test it already, and I based my code on previous stack data (if I am not wrong, the program starts with the digit to extract in Y and the number in X). After IPyou have: L X Y Z TWith the new code you have: L X Y Z Twhere: a  your nunmber n  digit to extract I  intermediate index V  digit position If you want to preserve a copy of the original number (a), you can use this version (same length): *LBL L ! Hope this helps.
Luiz (Brazil) Edited: 22 Nov 2005, 4:06 p.m.
Re: Help Squeezing some HP67/97 code  Howard Owen  11222005 Very cool, Luiz! I figured there were better ways to do the stack manipulations, and this fits the bill perfectly. I have quite a ways to go to get it all to fit into 224 steps on the 97, but if I can milk more code for a line here and there, I might just make it. First I'm going to finish with the 33S version, to get a concrete target to shoot at. Thanks!
Regards, Re: Help Squeezing some HP67/97 code  Vieira, Luiz C. (Brazil)  11222005 Hi, Howard; I know what you mean, believe me. I'm actually having some good experiences with sqweezing some original TI59 programs to the HP67/97. I had to virtually 'crack the code' in some pieces, but one of the main achievements of mine was a couple of months ago, when I could generate an equivalent HP97 code with 3 parts (three mag cards) from an original TI59 also threeparts program. The fact is that the three HP97 parts together are a bit bigger than one of the three original TI59 parts. And it works perfectly fine... Success!
Luiz (Brazil)
Re: Help Squeezing some HP67/97 code  Valentin Albillo  11232005 Hi, Howard:
If you ever decide to port your YATZ program to the HP71B, this does the trick: VAL(STR$(N)[P,P])where N is your number and P is the desired digit's position. So, for instance, if N is 3141592654 you would have: VAL(STR$(N)[1,1]) > 3, the digit at the 1st positionand so on. Also, should you decide to port your game to the HP15C, these steps will do: STO RAN#assuming the digit positions are counted this way, for example for 3141592654: digit position 0 1 2 3 4 5 6 7 8 9so, with the desired position in Y and the orig. number in X, executing the above steps would do the following (say you want the digit at position 6): T: T T: Zso your original number is preserved intact in Y, the desired digit is of course in X, plus the original contents of Z are preserved as well. If you want to count digit positions starting at 1 instead of 0, simply subtract 1 from Y after the X<>Y. The routine is quite fast as it uses no LOG instructions, just a single, integerargument 10^X, and would be even shorter if the HP15C had either the SIGN or the MOD (or RMD, remainder) functions builtin, which, alas, it doesn't ... nobody's perfect. BTW, I have no HP15C at hand right now, but believe the above steps are correct.
Best regards from V. Edited: 23 Nov 2005, 7:11 a.m.
Re: Help Squeezing some HP67/97 code  Etienne Victoria  11232005 Hi Valentin, Maybe I missed something but Howard's YATZ IS a 71B program :) Regards
Etienne
Re: Help Squeezing some HP67/97 code  Valentin Albillo  11232005 Hi, Etienne:
I've read this whole thread again and didn't find any
Best regards from V.
Re: Help Squeezing some HP67/97 code  Eamonn  11232005 Hi Howard, You would need to see how this suggestion would affect the rest of your program, but if it is possible to change the way you store numbers so that you can end up having to extract the n'th digit counting right to left, instead of from left to right, then you could use the following:
L0001 LBL L As an example, if Y contains 3 and X contains 1234567, then this routine will return 5. Additionally, if it is possible to have the digit to be extracted in the X register and the original number in the Y register, then the x<>y on line 2 can be removed, saving another step in this function. Again, you would have to evaluate how this may or may not impact the rest of your program. Best Regards,
Eamonn.
Re: Help Squeezing some HP67/97 code  Howard Owen  11232005 Yes, the 71B version was the first one I did. But it doesn't use the same approach to encoding the dice as digits in a five digit number. Since the BASIC has arrays, I just used those. The "grand tour" is a project to implement the Yahtzee dice game on all of the programmable platforms in my collection, or on as many as I can. Each version will try to take advantage of the features, and work within the constraints of the particular platform. The point of the exercise is to familarize (or refamilarize) myself with programming on each of the platforms in question. I also intend to write about each implementation, giving my personal history with the particular machine, as well as any unique challenges or features that interest me. So far I've done the 71B and the 9816, both in BASIC. The encoding scheme used here comes from the original program, which is not my software. It's a 41C program that I thought was either here or on TOS, but I can't locate it either place at the moment. I haven't studied the source, but I've played the game quite a bit. It shows the dice as a string of five digits, sorted in ascending order lefttoright. The user enters another number consisting of digit positions in the first string. This works pretty much as in Valentin's diagram, except the first (leftmost) digit is digit "1".
It bothers me that I can't locate the original HP41 program now. I have the program itself, so that's not a concern. But I really do need to attribute the original program as well as I can to the original source.
Re: Help Squeezing some HP67/97 code  Howard Owen  11232005 STO RAN# Devilishly clever! I suppose I shouldn't have expected less from you. 8) From the HP15C manual, page 48:
Quote:Italics are mine. The manual doesn't say how the number is "converted" but testing shows it takes place in the most straightforward way: the number is scaled down to be less than 1 by dividing it appropriately by powers of ten. Thus we have a microcoded operator that replaces the logarithm and division, and some stack manipulaton. Presumably this is much faster, though I haven't timed it. Since the game needs a "onebase" specifier, the above code needs to add a "1 " before the "10^X" but that hardly detracts from the suprise nature of the solution! Thanks, Valentin! I hadn't considered the 15C a suitable platform for this exercise, but with more tricks like that, I may well give it a try!
Regards,
Edited: 23 Nov 2005, 3:42 p.m.
Re: Help Squeezing some HP67/97 code  Valentin Albillo  11252005 Hi, Howard: Howard wrote:
"Devilishly clever! I suppose I shouldn't have expected less from you. 8)"
Best regards from V.
Re: Help Squeezing some HP67/97 code  Marcus von Cube, Germany  11252005 I understand that the original number has always 5 digits. If that's true, it's a waste to create a routine that can cope with aribtrarily long numbers. If you can't count from right (because it's the user that enters the digit positions and you do not want to change the user interface), just subtract the digit postion from 6.
L0001 LBL L Because of the sign change, the step L0006 (was L0004) now is * instead of /.
Marcus
Re: Help Squeezing some HP67/97 code  Howard Owen  11252005 Quote: Well, 338 bytes of memory, assuming most instructions are one byte, together with the ability to have duplicate forwardbranch labels, ought to allow me to implement the game of the 15C. Whether it will be a "work of art" remains to be seen. 8)
Quote: That rings a bell. But I don't find the game in my collection of User Library programs. There is no 41C program in the swap disks beginning with "Y," other than one named "Y," which isn't the one. So I must have picked it up online somewhere. But I don't see it here or on TOS. Please do let me know the original author's name and the User Library number, if you get a chance, Valentin. Thanks!
Regards,
Edited: 25 Nov 2005, 5:03 p.m.
Re: Help Squeezing some HP67/97 code  Howard Owen  11252005 Unfortunately, I need the generality because the user inputs a string of digits representing the "dice" to throw away in the five digit number. For example, if I had "22345" and I wanted to try for the twos, I would enter "354" (or any permutation) to throw away the "345" in the five digit string. If I wanted to try to turn the small straight into a large straight, I would enter "1" or "2" to throw away one of the twos. So the input number can be from 0 to 5 digits (0 is a special case meaning "score now") and it can have the "throwaway" digit positions in any order.
Re: Help Squeezing some HP67/97 code  Marcus von Cube, Germany  11262005 Howard, in this case, you can simply parse the string from the right. You'll get one digit after the other until the number is zero.
Marcus
Re: Help Squeezing some HP67/97 code  Howard Owen  11262005 Ah, but I want to avoid using a label, too, if I can. Especially on the 33S, where all labels are global. On the 97, I can branch forward to a label that can be repeated elsewhere. But a loop that will process any number of digits, up to five, requires a backward branch. On the 33S, I could unroll the loop, trading labels for lines. I'd have to set a flag and return on that to avoid a forward branch there. But trading lines for labels is not an option on the 97. There I'm already running into the line limit.
So what I need is code that uses few lines and no labels. So far, Luiz has the best code that fits the bill on the 33S, and also the 97. Valentin's trick of using the random seed initialization on the 15C is the overall winner, but it only works on the 15C.
