HP Forums

Full Version: (33s) OEIS A68637: Maximum of Input & Reversal
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Due to huge lack of labels on 33s I clumsily use flags - as there is only one flag test (FS?) I use two flags.

Can anyone suggest a more economical approach?

Takes a real integer from the stack & returns A68637(N), to stack.

https://oeis.org/A068637

Returns maximum of N & reversal.
Preserves stack.

Code:
1.    LBL B
2.    CF 1
3.    SF 2
4.    STO A
5.    XEQ R
6.    RCL- A
7.    x>0?
8.    SF 1
9.    FS? 1
10.    RCL+ A
11.    FS? 1
12.    CF 2
13.    FS? 2
14.    CLx
15.    FS? 2
16.    RCL+ A
17.    CF 1
18.    CF 2
19.    RTN

B: LN = 57

Reverso.
Reverses the order of digits in stack level X.
eg 1234 becomes 4321.
Preserves 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
(08-11-2022 04:06 AM)Gerald H Wrote: [ -> ]Due to huge lack of labels on 33s I clumsily use flags - as there is only one flag test (FS?) I use two flags.

Can anyone suggest a more economical approach?

Without any flag:

Code:
01.    LBL B
02.    STO A
03.    XEQ R
04.    RCL- A
05.    x>0?
06.    STO+ A
07.    x<> A
08.    RTN
Thank you, Didier, a lesson in economy!
I'm glad to see you posting OEIS sequence programs again. They are always interesting and fun. This one particularly reminds me of your thread here which resulted in the ListExt function REV for the 49g/50g. That reduces the program to the trivial DUP REV MAX in RPL.
(08-11-2022 01:04 PM)Gerald H Wrote: [ -> ]Thank you, Didier, a lesson in economy!

You already had half of the solution Smile

Here the goal was to get the max of X and A in the minimum steps, you already had RCL- A and x>0?, after that the flags management was adding a lot of complexity. I removed all these flags instructions, looked at what was remaining and realized that we had R-A in X and by adding it to the register A after the x>0? we would get R in this register if R was bigger than A or A if it was lower, then x<> A to not disturb the stack and we have the max of X and A in 4 steps.
Reference URL's