Re: Short & Sweet Math Challenges #8: TI-95 beats HP 42S « Next Oldest | Next Newest »

 ▼ Marcus von Cube Member Posts: 74 Threads: 10 Joined: Jan 1970 05-04-2005, 12:38 PM This is a follow up on an archived message: I've ported my algorithm to my trusty TI-95 PROCALC, a machine I baught when they still were in the shops. If you own the PC-Interface, you can compile the source with TIC95.EXE and load it into your calc. The program presents a menu with 4 selections: F1:GO Run the loop F2:TST Run a single test on one number, displays the smallest digit. F3:DIG Set number of different digits (2 or 3), 2 is default F4:BEG Set beginning of loop, default is 33334. For F3/F4, you have to enter the number and then press the key. The most interesting result for me was that the TI-95 is noticably faster than my HP 42 (some 10 to 20% percieved). The algorithm is essentially the same. The programming model in both calcs is comparable. TI's comparison statements work against registers (no longer the "t" register only). In many cases I had to store a value in a register on the TI where I could use the stack on the HP. Registers can be accessed by letters but this is just a shorthand notation to the corresponding numbers (RCL 000 is the same as RCL A). The flags are used just the opposite way in my HP implementation and in this program: On the HP, I reset a flag when a corresponding digit is found while I set a flag on the TI. The reason is simple: the HP has a FC?C instruction that tests and clears a flag in one step. The feature is missing on the TI so I could use the more natural approach of setting the flags instead or clearing them. Another missing feature on the TI is MOD: I had to use a more complicated formula to get the last digit. Some statements can only be entered in so called unprotected (system) mode. These are SBA 226, a call to an assembly routine which does a VIEW (not available on the keyboard), and STB 00xx, which stores a byte in memory. The latter is used to clear the flags. After entering the program you can speed it up with the ASM key: it replaces all (slow) label jumps by absolute jumps. INV ASM undoes the change. Here is the program: ```' ' Find 10 digit squares with at most 2 or 3 different digits ' DFN CLR DFN F1:GO @GO ' Start computation DFN F2:TST@TT ' Test a single value DFN F3:DIG@DD ' Set # of different digits (2, 3) DFN F4:BEG@BB ' Set first guess 2 SBL DD ' Default: 2 different digits 33334 SBL BB ' First guess to square & test CLR HLT LBL AA ' check a value against # of digits INC H ' some statistics SBA 226 ' display without delay STO A ' scratch register for value 0 STB 0028 ' system register: Flags 0-7 STB 0029 ' system register: Flags 8-15 STO C ' clear # of digits found so far LBL A1 ( ' compute A MOD 10 and INT( A / 10 ) RCL A - ( / 1 0 ) INT STO A ' this is INT( A / 10 ) * 10 ) ' this is A MOD 10 (last digit of number) STO B ' use B for indirect flag setting INV TF IND B INC C ' digit not yet encounterd, count it SF IND B ' mark digit RCL C ' get count IF> D ' compare to maximum digits SF 00 ' too many digits TF 00 ' tested number has failed RTN ' (0 encountered or too many digits) 0 ' all digits tested? IF= A RTN ' done GTL A1 ' next digit LBL CC ' get smallest valid digit for next guess RCL C ' # of digits found IF= D ' is the allowed maximum? GTL C1 ' find the smallest digit encounterd 1 ' not all allowed digits in last try RTN ' must return 1 LBL C1 1 ' digit index starts with 1 STO B LBL C2 TF IND B ' is digit in last tested number? RTN ' yes, must be the smallest INC B ' next digit RCL B ' get it (in case of return) GTL C2 ' loop LBL DD ' store # of allowed digits (key F3) STO D RTN LBL BB ' store first number to square STO E ' compensate for INC E in main loop INV INC E 0 ' initialize counters and comparison values STO F ' first 4 digits STO G ' first 3 digits STO H ' total # of checks RTN LBL GO ' main loop starts here (key F1) INC E ' next # to square 99999 ' check end of loop INV IF> E GTL ZZ ' done ( ' compute first 4 digits of squared # RCL E x^2 / 1000000 ) INT INV IF= F ' same 4 digits as last try? SBL FF ' no, get next guess based on first 4 digits RCL E ' get number again x^2 ' and square it SBL AA ' digit test routine INV TF 00 ' check it test passed SBL PR ' got it, show/print result GTL GO ' next guess LBL FF ' find a new guess based on first 4 digits STO F LBL F1 RCL F ' 4 digits to test ( ' check if first 3 digits have changed / 10 ) INT INV IF= G SBL GG ' check first 3 digits first RCL F ' get current guess SBL AA ' test it INV TF 00 GTL F2 ' test passed: compute new guess for main loop INC F ' test failed, try next 4 digit number GTL F1 LBL F2 ' compute a new guess ( ( RCL F ' first 4 * 10 ' shifted 1 left + SBL CC ' add smallest possible next digit ) * 100000 ' shift 5 left + 11110 ' offset which can be added safely ) SQR ' the INT of the square root is next guess INT STO E ' store it INC E ' our guess was still too small RTN LBL GG ' find a new guess based on first 3 digits STO G ' 3 digits to test LBL G1 RCL G ' get current guess SBL AA ' test it INV TF 00 GTL G2 ' test passed: compute new guess for FF loop INC G ' test failed, try next 3 digit number GTL G1 LBL G2 ' compute a new guess ( RCL G ' first 3 * 10 ' shifted 1 left + SBL CC ' add smallest possible next digit ) STO F ' store it RTN LBL PR ' print or show a valid result RCL E ' number to be squared PRT x~t ' save in t-Register RCL E x^2 ' squared number in display PRT INV TF 74 BRK ' halt if no printer connected RCL C ' number of different digits PRT ( ' flag word RCB 0028 + RCB 0029 * 256 ) HEX ' print it in HEX PRT DEC ' revert to normal display RTN LBL TT ' test a single value (key F2) SBL AA ' call test routine 0 TF 00 HLT ' stop and show 0 if test failed SBL CC ' show smallest digit or 1 if less then HLT ' the allowed number were found LBL ZZ ' end of main loop RCL H ' show number of checks PRT HLT END ``` ▼ Namir Posting Freak Posts: 2,247 Threads: 200 Joined: Jun 2005 05-04-2005, 12:51 PM Marcus .. you and I are soul brothers!!! I thought no one cared about the TI-95 machine. It is a cool programmable calculator and I am glad you are making it shine! Namir Marcus von Cube Member Posts: 74 Threads: 10 Joined: Jan 1970 05-04-2005, 02:08 PM Performance is better than I first thaught. After an hour, the calc had tested *all* 2 digit combinations (5142 total) and printed out the correct result 81619²=6661661161. HrastProgrammer Senior Member Posts: 381 Threads: 32 Joined: Mar 2006 05-05-2005, 01:48 AM Hello Marcus, Great work! Could you, if you have some free time, of course, download my TI-95 emulator for Windows from http://www.geocities.com/hrastprogrammer, enter this program into the emulator and compare the result with the real calculator? As it is based on the real TI-95 ROMs I suppose the result must be the same but you never know ... Best regards. ▼ Marcus von Cube Member Posts: 74 Threads: 10 Joined: Jan 1970 05-05-2005, 06:12 AM Hi Hrastprogrammer! I first found TI95E in September 2004. I checked the download and it's still the most recent version. (I'd like to see the PC interface emulated, a cartridge add/remove dialog, ...) The program yields the exact same results as on the real machine, except the time (in full speed mode): The complete 2 digit run was a matter of a minute! Steps to transfer the program: 1. On the real machine, store it in the cartridge 2. Use the PC interface and program PCA to save the cartrige to a file. 3. Transfer the file to the emulator directory and use my program ti95cart to incorporate the cartrige file in the memory image. The program can than be started from the emulated RAM. If you drop me a mail, i'll respond with my files. Marcus P.S.: The emulator runs fine under OS/2 with Odin installed! I still prefer it over Windows on my main system. ▼ HrastProgrammer Senior Member Posts: 381 Threads: 32 Joined: Mar 2006 05-05-2005, 09:47 AM I first found TI95E in September 2004. I checked the download and it's still the most recent version. (I'd like to see the PC interface emulated, a cartridge add/remove dialog, ...) I would like to see these things implemented, as well :-) But I don't have any info about the interface and I don't have any cartridge to test module loading :-( You have my e-mail address on my homepage so you are welcome to send your files ... Best regards. ▼ Marcus von Cube Member Posts: 74 Threads: 10 Joined: Jan 1970 05-06-2005, 02:36 AM Hi HrastProgrammer, you can find a lot of technical info on the following ftp server: You'll need the free Scansoft PaperPort Viewer to read the ".max" files. I've put my files (and some of TI's) here: http://www.mvcsys.de/download/ti95.zip (ti95card.exe is an untested DOS compile but the source is included) ▼ HrastProgrammer Senior Member Posts: 381 Threads: 32 Joined: Mar 2006 05-06-2005, 09:28 AM Thank you for the files, especially for MATH and STAT cartridges. I modified my TI-95 emulator so now cartridges can be loaded, saved and cleared ... You can download the new version from my homepage http://www.geocities.com/hrastprogrammer. Best regards. ▼ Gene Posting Freak Posts: 1,107 Threads: 159 Joined: Jan 1970 05-06-2005, 09:54 AM I can't believe you cranked that out so fast. Thanks! ▼ HrastProgrammer Senior Member Posts: 381 Threads: 32 Joined: Mar 2006 05-06-2005, 10:24 AM I can't believe you cranked that out so fast. Thanks! I had to take a break while working on Voyager emulators :-) ▼ Gene Posting Freak Posts: 1,107 Threads: 159 Joined: Jan 1970 05-06-2005, 10:52 AM I said nothing was in here. :-)

 Possibly Related Threads... Thread Author Replies Views Last Post Need help understanding math.... cyrille de Brébisson 9 880 12-13-2013, 02:23 AM Last Post: Didier Lachieze HP Prime - Short "learning" modules CR Haeger 1 328 11-27-2013, 02:13 PM Last Post: Jonathan Cameron I have written a short introduction to the HP Prime Michael Carey 7 750 11-18-2013, 08:04 PM Last Post: Michael Carey HP Prime vs TI : Factoring ? HP Pioneer 7 654 10-29-2013, 02:00 PM Last Post: CompSystems HP-65 short circuit Ignacio Sánchez 2 389 10-22-2013, 08:27 AM Last Post: Ignacio Sánchez Reig OT: a math competition site Pier Aiello 0 246 09-16-2013, 06:03 AM Last Post: Pier Aiello Simple Math Question Namir 2 336 08-09-2013, 06:13 PM Last Post: Eddie W. Shore Cool math clock Bruce Bergman 28 1,885 04-10-2013, 03:13 AM Last Post: Siegfried (Austria) HP-71B - thanks to Marcus von Cube for MATH ROM article Michael Lopez 2 339 03-03-2013, 07:19 AM Last Post: Paul Berger (Canada) FRAM71 for HP-71B, short update #3 Hans Brueggemann 15 1,036 01-20-2013, 10:22 AM Last Post: Jerry Raia

Forum Jump: