Post Reply 
HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
09-12-2022, 02:53 PM
Post: #21
RE: HHC 2022 - Programming Contest - no responses until after 6am Monday 6am CENTRAL
Here is a version for the HP-28 and 48 only, it would need to be modified for the HP 49/50 because of decimal points in approximate numbers.

Code:

\<< 0 SWAP                  @ Counter = 0
  DO DUP NREV +             @ Reverse and add
    SWAP 1 + SWAP           @ Increment counter
  UNTIL DUP2 \->STR "E" POS @ Is >= 10^12?
    SWAP 50 \>=             @ Count >= 50?
    IF OR
    THEN DROP2 0 DUP 1      @ Replace with two zeros
    ELSE DUP DUP NREV SAME  @ Exit main loop if palindrome
    END
  END
\>>

It calls the following program NREV which reverses the digits of an integer.

Code:

\<< \->STR "" OVER SIZE 1
  FOR k OVER k DUP SUB + -1
  STEP SWAP DROP STR\->
\>>
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 - John Keith - 09-12-2022 02:53 PM



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