Programming Challenge: Palindromic Numbers on HP 50g
|
01-13-2018, 10:23 AM
Post: #1
|
|||
|
|||
Programming Challenge: Palindromic Numbers on HP 50g
I just published 2 programmes for producing palindromic numbers
http://www.hpmuseum.org/forum/thread-9921.html & they work very nicely. They may be of use in this challenge (or not). The problem now is how to interleave the 2 sequences so as to produce https://oeis.org/A002113 ie all the palindromic numbers in their natural order as in the OEIS reference. I would like a UserRPL programme that for input, say 98765432167 returns the 98765432167th member of the series. Special merit given for short programmes & even more so for speedy ones. |
|||
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 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. |
|||
01-13-2018, 05:09 PM
(This post was last modified: 01-13-2018 06:24 PM by Gilles59.)
Post: #3
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
This works both in UserRPL (exact mode) and NewRPL (1E31 SETNFMT to get all the signifiant digits) . Naive approach
Code: « In NewRPL with the simulator, you can see that : 1000 Palin -> 90009 (0.081 sec on the simulator, 4.5s on the NewRPL-HP50g, UserRPL : 76 sec with Emu48 FastMode, sloooow with a stock HP50 ) 2000 Palin -> 1000001 3000 Palin -> 2000002 etc. 5000 Palin -> 4000004 (Simulator : 3,3 sec - NewRP HP50g : 190sec ) So we can imagine a way for a less naive approach for big numbers ;D |
|||
01-13-2018, 06:48 PM
Post: #4
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
HP-42S version of my program:
Code: 00 { 85-Byte Prgm } 5000 XEQ "PALIN" => 4000004 in 1.23 seconds (HP-42S). Of course it's faster in Free42 or in a DM42, and then you can get palindromes up to 34 digits. 98765432167 XEQ "PALIN" => 887654321676123456788 in 0.01 seconds (DM42). |
|||
01-13-2018, 09:53 PM
Post: #5
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
Very nice, Thomas, & here a slightly altered version which will deal with the entry 98765432167 & return the correct answer!
By the way, SAME is much faster than ==. NTOK Code: « DUP 10 <= NREV Code: « 0 |
|||
01-13-2018, 11:21 PM
Post: #6
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-13-2018 09:53 PM)Gerald H Wrote: Very nice, Thomas, & here a slightly altered version which will deal with the entry 98765432167 & return the correct answer! Thanks! My code is a bit limited by the fact that I do these RPL challenges in m48 on my iPhone, and that means I'm effectively using a 48GX. I see that m48+ emulates the 49G+ as well; is that equivalent to a 50g, software-wise, or should I look specifically for a 50g emulator? |
|||
01-13-2018, 11:32 PM
Post: #7
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-13-2018 11:21 PM)Thomas Okken Wrote: I see that m48+ emulates the 49G+ as well; is that equivalent to a 50g, software-wise, or should I look specifically for a 50g emulator? The 49g+ and 50g are functionally identical - the only differences were in the h/w. The latest f/w release is 2.15, so check if that's installed ("VERSION") and if not, I'd upgrade it, assuming the emulator allows that. --Bob Prosperi |
|||
01-14-2018, 01:30 AM
Post: #8
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-13-2018 11:32 PM)rprosperi Wrote:(01-13-2018 11:21 PM)Thomas Okken Wrote: I see that m48+ emulates the 49G+ as well; is that equivalent to a 50g, software-wise, or should I look specifically for a 50g emulator? I installed m48+, selected 49G+ emulation. VERSION reports 2.15. Sweet, thanks! Good to go and explore something new. (New to me, anyway. ) |
|||
01-14-2018, 06:30 AM
(This post was last modified: 01-14-2018 04:14 PM by Gerald H.)
Post: #9
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
Edit: Programme cleansed of inaccurate symbols.
A faster version, obviating REV NNTOK Code: « DUP 10 ≤ |
|||
01-14-2018, 01:11 PM
Post: #10
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 06:30 AM)Gerald H Wrote: A faster version, obviating REV I tried running this in m48+ emulating the 49G+, and it doesn't recognize SREV. The calculator has all the default settings; all I did before entering the program was switch from ALG to RPN mode. I should obviously read the manual, and I will, but is there a quick fix for this problem? |
|||
01-14-2018, 01:59 PM
(This post was last modified: 01-14-2018 02:01 PM by Gilles59.)
Post: #11
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 01:11 PM)Thomas Okken Wrote: I tried running this in m48+ emulating the 49G+, and it doesn't recognize SREV. Hi, try -86 SF For 'infinite integer" RightShift & ENTER (toggle Real mode and exact mode) |
|||
01-14-2018, 02:06 PM
Post: #12
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g | |||
01-14-2018, 02:10 PM
(This post was last modified: 01-14-2018 02:11 PM by Gilles59.)
Post: #13
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 02:06 PM)Thomas Okken Wrote:Try ON & F3 (in the same time) like when you attch a lib(01-14-2018 01:59 PM)Gilles59 Wrote: -86 SF Extract of AUR : Quote:The Development Library |
|||
01-14-2018, 02:17 PM
Post: #14
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g | |||
01-14-2018, 02:37 PM
Post: #15
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 02:17 PM)Gerald H Wrote:(01-14-2018 02:06 PM)Thomas Okken Wrote: That didn't work -- it's still not recognizing SREV. @Thomas - after setting the flag (or attaching), press [APPS] to verify the "Development lib" is present as App #15 at the bottom. Selecting it should change the menu to [->H], [H->]. etc. SREV is on the 3rd page (press [NEXT] twice]). --Bob Prosperi |
|||
01-14-2018, 02:46 PM
Post: #16
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
Ah, so I was missing the ON+F3 step.
Did that, and now SREV works! The program still doesn't work, with the same error message as before, which I'm guessing means that it needs to be re-parsed first. Next challenge: find the EDIT command. Boy, this keyboard layout really looks nothing like the 48G. I really have to start reading the manual, I don't want to spam this thread with 49G+ rookie questions. Thank you Gerald, Gilles, and Bob, for helping me get started! |
|||
01-14-2018, 03:51 PM
(This post was last modified: 01-14-2018 03:54 PM by Gilles59.)
Post: #17
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g | |||
01-14-2018, 04:05 PM
Post: #18
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
If you enter RCLF you will recall your flag settings.
My flag settings are { # 3800030205010FF0h # 8000000000000000h # 1000040A000008h # 0h } If you enter this list & then STOF you will have the same flag settings as me. |
|||
01-14-2018, 04:10 PM
(This post was last modified: 01-14-2018 04:15 PM by Gilles59.)
Post: #19
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
(01-14-2018 06:30 AM)Gerald H Wrote: A faster version, obviating REV Beautiful ! Works fine for me (in exact mode and with correct <= and >= characters)/ Now i have do understand_why_ this works |
|||
01-14-2018, 04:10 PM
Post: #20
|
|||
|
|||
RE: Programming Challenge: Palindromic Numbers on HP 50g
The <= in the programme as depicted in the thread does not exist on 50g - correct form is
≤ Similarly >= is ≥ |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 26 Guest(s)