Post Reply 
HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
09-12-2022, 08:30 PM (This post was last modified: 09-12-2022 08:33 PM by C.Ret.)
Post: #25
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
Ha, Ha !

I finally and not without difficulty, succeeded in adapting my code to the rules of the game. I used an algorithmic shortcut which made it stop when the user entered a palindromic integer.

I thought I was going crazy; I turned like a fool any subsets of my code in all the directions and , the only versions that worked by correctly applying the rule were too long, too slow too complex.

It is only in the evening that I had the idea of using the user flag FLG 00 and I was able to adapt my original version cheaply.

The code I obtained is very similar to Werner's, at least in its operating principle.
On the other hand, the calculations made and the registers used have nothing comparable. In fact, it is greatly different in the details and a bit longer code:

51 bytes (without global alpha LaBeL and END), three registers and a flag.

(09-12-2022 01:51 PM)Werner Wrote:  My first try, 41-compatible, needs 1 register (00 here)
41: 42 bytes without LBL and END.

Code:
00 { 54-Byte Prgm }
01▸LBL "HHC2022"
02   STO 00  STO- 00  XEQ 10
05  ▸LBL 03                                                      @ main loop
06     +  XEQ 10  ISG 00  X<>Y  X≠Y?  GTO 03
12   RCL 00  X<>Y  RTN                                     @ end

15▸LBL 10                                                        @ reverse number X -> revX X
16   ENTER  ENTER  -  10  LASTX
21  ▸LBL 02
22     %  FP  STO+ Z  R↓  ST* Y  LASTX  INT  X≠0?  GTO 02
31     R↓  R↓
33 END

Good code, I need to study how the NUMBER INVERSION procedure works; the percent % statement piques my curiosity.

On the other hand, I don't see anywhere where the control of the maximum number of loops or the detection of the maximum capacity of ten digits is done?!?

My code is 10 bytes longer, but it does all the due checks and it returns Y:0 X:0 on overflow digit capacity or loop number.
Code:
001 STO 01  SF 00  51 STO 02  0 STO 03    @ R01:actual integer   R02:cycles limit   R03:addition's counter                           
007 LBL 01                                                       @   MAIN LOOP
008   0  RCL 01
010   LBL 02  STO Z  10  ST/ T  ST* Z  MOD  +  X<>Y  INT  x>0?  GTO 02  @ REVERSE R01 digit by digit
021   10^X  10^X  X<>Y  RCL 01  FC?C 00  X≠Y?  ISG 03  GTO 03           @ If palindrome then exit but not first time :)
029   +  STO 01 (VIEW 01)                                               @ Update R01 ← R01+Pal(R01) 
031   LOG  x>Y?  CLRG                                                   @ Test for overflow ten digits
034 DSE 02  GTO 01                                                      @ Countdown and loop
036 CLRG                                                                @ CLEAR all REGISTERS to zero R01 and R03
037 LBL 03
038 RCL 03  RCL 01 (TONE 5)                                      @ END with Y:nb cycle  and X:final palindrome

   


Well, I haven't found any integers that approach the 50 iterations limit without exceeding the 10 digits limit!
Besides, I had a hard time finding an integer that don't give a palindrome in a few turns of the wheel!

Sadly, the main part of all the integers I try have a tendency to rapidly form a palindrome.
At least 196 works!

P.S.1:
Attention, in case of overflow, my code resets all the registers to zero. I'm a lazy person who doesn't try to preserve anything and finds it fine to use CLRGs shorter than 0 STO 03 STO 01.

P.S.2:
The printed version contains on step 31 a VIEW 01 to see what is happening and on step 41 a TONE 5 to sound the end of the race. These two statements are optional. If I could have been present at HHC 2022, they would not have appeared on the copy I would have given to the jury.

Thanks for sharing this. I had a lot of fun developing my code on my old, robust and reliable HP-41C
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL - C.Ret - 09-12-2022 08:30 PM



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