Post Reply 
HHC 2021 Programming Contests - Surprise !
10-21-2021, 09:17 AM (This post was last modified: 10-25-2021 02:08 PM by Werner.)
Post: #41
RE: HHC 2021 Programming Contests - Surprise !
Update 20211025: yet another correction.... hopefully the last one! 88 bytes on the 41.
Corrected version.. 42S-style listing, even shorter ;-)
To catch an input of all 9's, I simply add 1 to the number at the beginning, and stop if
the palindrome formed by mirroring the first half is larger or equal to the original.
Code:
00 { 96-Byte Prgm }
01▸LBL "PAL"
02 FIX 00
03 CF 29
04 1
05 +
06 CLA
07 ARCL ST X
08 XEQ 14
09 ALENG
10 2
11 MOD
12 X=0?
13 GTO 00
14 -
15▸LBL 02
16 1
17 +
18 10
19 ÷
20 IP
21 LASTX
22 XEQ 10
23 X<Y?
24 GTO 02
25 RTN
26▸LBL 00
27 SIGN
28 -
29▸LBL 03
30 1
31 +
32 10
33 %
34 XEQ 10
35 X<Y?
36 GTO 03
37 RTN
@     add reverse digits of number
38▸LBL 10
39 ENTER
40 FP
41 STO+ ST Z
42 -
43 10
44 STO× ST Z
45 ÷
46 X>0?
47 GTO 10
48 +
49 X<Y?
50 X=Y?
51 RTN
52 R↓
@     leading half: abcd -> ab, abcde -> abc
53▸LBL 14
54 STO ST Y
55 ALENG
56 2
57 ÷
58 IP
59 10^X
60 ÷
61 IP
62 END
Cheers, Werner

41CV†,42S,48GX,49G,DM42,DM41X,17BII,15CE,DM15L,12C,16CE
Find all posts by this user
Quote this message in a reply
10-25-2021, 02:09 PM
Post: #42
RE: HHC 2021 Programming Contests - Surprise !
I had managed to shave two steps out of my earlier versions and figured that was about the best I could do, or at least maybe the best I should do so as to stop spending time on this particular challenge. I was going to update my original listings above with the slight improvement and call things good when I saw Werner's above post:

(10-21-2021 09:17 AM)Werner Wrote:  To catch an input of all 9's, I simply add 1 to the number at the beginning, and stop if
the palindrome formed by mirroring the first half is larger or equal to the original.

I find the above to be fairly brilliant. Applying this concept to my program shaved off 19 steps. Now down to 53 steps, 86 bytes. The latest and most likely greatest (for me, at least) version is below. Handles inputs greater than or equal to 0. (I would file a protest with the proper authorities if the judge used a negative number as a test case.)

Code:
00 { 86-Byte Prgm }
01▸LBL "PAL"
02 FIX 00
03 CF 29
04 CF 01
05 CLA
06 1
07 +
08 STO 01
09 ARCL ST X
10 ALENG
11 2
12 ÷
13 FP
14 X≠0?
15 SF 01
16 X<>Y
17 LASTX
18 IP
19 10^X
20 ÷
21 IP
22 STO 03
23 XEQ 50
24 RCL 01
25 X<>Y
26 X≥Y?
27 STOP
28 RCL 03
29 1
30 +
31 XEQ 50
32 STOP
33▸LBL 50
34 0.1
35 RCL× ST Y
36 ENTER
37 FC? 01
38 RCL ST Z
39 IP
40▸LBL 01
41 10
42 STO× ST Z
43 ÷
44 X=0?
45 GTO 00
46 ENTER
47 FP
48 STO+ ST Z
49 -
50 GTO 01
51▸LBL 00
52 R↓
53 END

Dave - My mind is going - I can feel it.
Find all posts by this user
Quote this message in a reply
Post Reply 




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