Post Reply 
Programming Challenge: Palindromic Numbers on HP 50g
01-14-2018, 04:41 PM
Post: #21
RE: Programming Challenge: Palindromic Numbers on HP 50g
As the weekend draws to a close (here in Vienna) I post my attempt at answering the challenge.

The programme takes about half the time needed by NNTOK above.

The poetic name of the programme is

A002113.USR

Code:
« DUP 2. <
  IF
  THEN 0
  ELSE DUP →STR DUP
HEAD "1" SAME OVER
2. 2. SUB "0" SAME
NOT AND
    IF
    THEN TAIL DUP
SREV
    ELSE DUP TAIL
SWAP HEAD OBJ→ 1 -
DUP NOT
      IF
      THEN DROP
TAIL 9
      END
SWAP + DUP SREV
TAIL
    END + OBJ→
  END SWAP DROP
»
Find all posts by this user
Quote this message in a reply
01-14-2018, 07:50 PM
Post: #22
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 03:51 PM)Gilles59 Wrote:  To edit a program I press :

' (the O key)
The key of the soft menu of the program i want to edit
ENTER
LeftShift & DownKey

The way I do it:

RightShift
Program name softkey
DownArrow

Then when done editing:

Enter
LeftShift
Program name softkey.
Find all posts by this user
Quote this message in a reply
01-14-2018, 09:14 PM
Post: #23
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 04:10 PM)Gilles59 Wrote:  Now i have do understand_why_ this works

I approached it like this:
Palindromes with an odd number of digits have the form ABCDCBA
Palindtomes with an even number of digits have the form ABCDDCBA

therefore

There are 10 1-digit palindromes, 0-9.
There are 9 2-digit palindromes, 11-99.
There are 90 3-digit palindromes, 101-999.
There are 90 4-digit palindromes, 1001-9999.
There are 900 5-digit palindromes, 10001-99999.
There are 900 6-digit palindromes, 100001-999999.
etc.

So, adding up these numbers, the pattern is clear:
The first 1-digit palindrome is #1 (counting from 1, an arbitrary but convenient choice)
The first 2-digit palindrome is #11
The first 3-digit palindrome is #20
The first 4-digit palindrome is #110
The first 5-digit palindrome is #200
The first 6-digit palindrome is #1100
The first 7-digit palindrome is #2000
etc.

Once you see the pattern, the code practically writes itself.
Visit this user's website Find all posts by this user
Quote this message in a reply
01-15-2018, 01:17 AM
Post: #24
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 07:50 PM)John Keith Wrote:  
(01-14-2018 03:51 PM)Gilles59 Wrote:  To edit a program I press :

' (the O key)
The key of the soft menu of the program i want to edit
ENTER
LeftShift & DownKey

The way I do it:

RightShift
Program name softkey
DownArrow

Then when done editing:

Enter
LeftShift
Program name softkey.

Very useful tips, thank you!

I also noticed that RightArrow is SWAP, like on the 48G -- except on the 48G, it actually says so on the keyboard. Are these shortcuts documented anywhere?
Visit this user's website Find all posts by this user
Quote this message in a reply
01-15-2018, 02:18 AM (This post was last modified: 01-15-2018 02:20 AM by rprosperi.)
Post: #25
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-15-2018 01:17 AM)Thomas Okken Wrote:  I also noticed that RightArrow is SWAP, like on the 48G -- except on the 48G, it actually says so on the keyboard. Are these shortcuts documented anywhere?

Appendix G in the 50g User's Guide is probably the best single source, but Appendix G in the 50g AUR also includes some useful shortcuts that go beyond simple key assignments. The 50g User's Manual by contrast doesn't provide much useful info of this type, it's more focused on the math applications in the machine.

I assume you have these PDF Docs, but I'd suggest you get the versions with the index integrated into the PDF, it makes them much more useful.

--Bob Prosperi
Find all posts by this user
Quote this message in a reply
Post Reply 




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