Post Reply 
HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
09-12-2022, 12:41 PM (This post was last modified: 09-12-2022 01:08 PM by ThomasF.)
Post: #18
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
Hi,

An RPN solution for the 41 system (C/CV/CX/X).
The code assumes nothing except that the statistical registers are at the default location.
With only local labels I get the count to 58 bytes (47 without overflow check ...).

193 XEQ A -> X: 233332 Y: 8
4884 XEQ A -> X: 8836886388 Y: 13

Cheers,
Thomas

(Edit: Added line numbers )
(Edit again: Missed the small detail about overflow!)

Code:

Code below ...









01◆LBL A                          Entry point to the routine
02 CLΣ       x   .   .   .        Clear registers used
03 STO 11    x   .   .   .        Save (as sum in reg 11)
04◆LBL 00    x   .   .   .
05 XEQ 01    x'  .   .   .        Reverse the register 11
06 Σ+        n   .   .   .        Add to sum (reg 11)
07 XEQ 01    x'  .   .   .        Reverse the sum
08 RCL 11    x   x'  .   .        Recall the original number
09 1 E10     OV  x   x'  .        Check for overflow ...
10 X<=Y?
11 GTO 03                         Bail out ...
12 RDN       x   x'  .   .
13 X!=Y?     x   x'  .   .        If different it is not a palindrom
14 GTO 00    x   x'  .   .           ... then loop again
15 RCL 16    n   x   x'  .        Recall the number of loops (N)
16 X<>Y      x   n   x'  .        Fix stack
17 RTN                                Done!
18◆LBL 03
19 CLST
20 RTN       0   0   0   0        Overflow!
21◆LBL 01    .   .   .   .        Subroutine to return the reverse of register 11
22 CLST      0   0   0   0        Init stack
23 10        10  0   0   0
24 X<>Y      0   10  0   0
25 RCL 11    x   0   10  0
26◆LBL 02
27 ENTER     x   x   r   10
28 RUP       10  x   x   r
29 MOD       t   x   r   r        Get least significant digit
30 LASTx     10  t   x   r        
31 ST* T     10  t   x   r'       Shift the result
32 ST/ Z     10  t   x'  r'       Shift the original number
33 X<> T     r'  t   x'  10
34 +         r"  x'  10  10       Add LSD to the result
35 X<>Y      x'  r"  10  10
36 INT       x"  r"  10  10       Remove LSD from original number
37 X!=0?     x"  r"  10  10       Anything left to shift?
38 GTO 02    x"  r"  10  10          ... yes, then loop again
39 RDN       r"  10  10  x"       Return the reversed result
40 END

[35/45/55/65/67/97/80 21/25/29C 31E/32E/33E|C/34C/38E 41C|CV|CX 71B 10C/11C/12C/15C|CE/16C 32S|SII/42S 28C|S 48GX/49G/50G 35S 41X]
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 - ThomasF - 09-12-2022 12:41 PM



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