Post Reply 
(33s) OEIS A2113: Palindromes in Natural Order
08-05-2022, 12:54 PM (This post was last modified: 08-06-2022 12:12 PM by Gerald H.)
Post: #1
(33s) OEIS A2113: Palindromes in Natural Order
Edit: 2022-08-06 Simplification of lines 4 & 5 of programme P.

Some years ago I wrote a programme for 49G to produce the same numbers - not so difficult if you have possibility of treating numbers as text.

https://www.hpmuseum.org/forum/thread-9988.html

The poor 33s only has numerical capabilities so I have risen to the challenge.

The programme P uses three helper programmes T, H & R shown below P.

All of the four programmes preserve the stack. (Let's see you do that on 41C or 42S!)

Suggestions for improvements welcome.


Takes a natural number N from the stack & returns A2113(N) to stack, Nth palindrome in natural order.
Does not disturb stack.

Code:
1.    LBL P
2.    STO A
3.    CLx
4.    A-10
5.    x>0?
6.    GTO Q
7.    CLx
8.    A-1
9.    RTN
1.    LBL Q
2.    CLx
3.    ALOG(IP(LOG(A)))
4.    STO W
5.    CLx
6.    0.1
7.    RCL* W
8.    STO X
9.    CLx
10.    RCL A
11.    XEQ H
12.    ACOSH
13.    x≠0?
14.    GTO V
15.    CLx
16.    RMDR(IDIV(A:X):10)
17.    x=0?
18.    GTO U
19.    CLx
20.    RCL A
21.    XEQ T
22.    STO P
23.    XEQ R
24.    STO Q
25.    CLx
26.    P*W+Q
27.    RTN
1.    LBL U
2.    CLx
3.    (A+9*X-W)*X
4.    STO P
5.    XEQ R
6.    STO Q
7.    RCL/X
8.    GTO X
1.    LBL V
2.    CLx
3.    (A-W)*W
4.    STO P
5.    XEQ R
6.    STO Q
7.    RCL/ W
1.    LBL X
2.    IP
3.    x≠0?
4.    GTO Y
5.    CLx
6.    Q+W
7.    STO Q
1.    LBL Y
2.    CLx
3.    RCL Q
4.    XEQ T
5.    RCL+ P
6.    RTN

P: LN = 41 V: LN =28
Q: LN = 132 X: LN =24
U: LN = 35 Y: LN = 18 

Head.
Erases all but first digit of stack level X.
Does not disturb stack.

Code:
1.    LBL H
2.    STO N
3.    LOG
4.    IP
5.    10^x
6.    STO R
7.    CLx
8.    IDIV(N:R)
9.    RTN

H: LN = 36

Tail.
Erases first digit of stack level X.
Does not disturb stack.

Code:
1.    LBL T
2.    STO N
3.    LOG
4.    IP
5.    10^x
6.    STO R
7.    CLx
8.    RMDR(N:R)
9.    RTN

T: LN = 36

Reverso.
Reverses the order of digits in stack level X.
eg 1234 becomes 4321.
Does not disturb stack.

Code:
1.    LBL R
2.    STO N
3.    CLx
4.    STO R
1.    LBL S
2.    CLx
3.    10*R+RMDR(N:10)
4.    STO R
5.    CLx
6.    IDIV(N:10)
7.    STO N
8.    x≠0?
9.    GTO S
10.    CLx
11.    RCL R
12.    RTN

R: LN = 12
S: LN = 61
Find all posts by this user
Quote this message in a reply
09-02-2022, 02:50 AM
Post: #2
RE: (33s) OEIS A2113: Palindromes in Natural Order
Following this thread

https://www.hpmuseum.org/forum/thread-18742.html

a better version of HEAD:

Code:
1.    LBL X
2.    x=0?
3.    RTN
4.    STO N
5.    SQRT
6.    LOG
7.    IP
8.    ALOG
9.    x<> N
10.    RCL/ N
11.    IP
12.    STO N
13.    LOG
14.    IP
15.    ALOG
16.    x<> N
17.    RCL/ N
18.    IP
19.    RTN

X: LN = 57
Find all posts by this user
Quote this message in a reply
Post Reply 




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