Post Reply 
Programming Challenge: Palindromic Numbers on HP 50g
01-13-2018, 04:33 PM (This post was last modified: 01-13-2018 04:36 PM by Thomas Okken.)
Post: #2
RE: Programming Challenge: Palindromic Numbers on HP 50g
Code:
<< DUP 10
  IF <=
  THEN 1 -
  ELSE DUP DUP 2 / LOG IP ALOG SWAP OVER 11 *
    IF >=
    THEN 10 * SWAP OVER - SWAP OVER * SWAP REV +
    ELSE SWAP OVER - DUP 10 / IP REV 3 ROLLD * +
    END
  END
>>

'PALIN' STO

<< 0
  DO 10 * OVER 10 MOD + SWAP 10 / IP SWAP
  UNTIL OVER 0 ==
  END SWAP DROP
>>

'REV' STO

1 PALIN => 0
2 PALIN => 1
10 PALIN => 9
11 PALIN => 11
etc.

This uses standard math so it can only generate palindromes up to 12 digits, but I imagine it shouldn't be hard to modify for extended-precision math.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-13-2018 04:33 PM



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