Programming Challenge: Palindromic Numbers on HP 50g - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Programming Challenge: Palindromic Numbers on HP 50g (/thread-9922.html) Pages: 1 2 |
Programming Challenge: Palindromic Numbers on HP 50g - Gerald H - 01-13-2018 10:23 AM 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. RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-13-2018 04:33 PM 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. RE: Programming Challenge: Palindromic Numbers on HP 50g - Gilles59 - 01-13-2018 05:09 PM 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 RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-13-2018 06:48 PM 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). RE: Programming Challenge: Palindromic Numbers on HP 50g - Gerald H - 01-13-2018 09:53 PM 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 RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-13-2018 11:21 PM (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? RE: Programming Challenge: Palindromic Numbers on HP 50g - rprosperi - 01-13-2018 11:32 PM (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. RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-14-2018 01:30 AM (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. ) RE: Programming Challenge: Palindromic Numbers on HP 50g - Gerald H - 01-14-2018 06:30 AM Edit: Programme cleansed of inaccurate symbols. A faster version, obviating REV NNTOK Code: « DUP 10 ≤ RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-14-2018 01:11 PM (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? RE: Programming Challenge: Palindromic Numbers on HP 50g - Gilles59 - 01-14-2018 01:59 PM (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) RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-14-2018 02:06 PM (01-14-2018 01:59 PM)Gilles59 Wrote: -86 SF That didn't work -- it's still not recognizing SREV. RE: Programming Challenge: Palindromic Numbers on HP 50g - Gilles59 - 01-14-2018 02:10 PM (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 RE: Programming Challenge: Palindromic Numbers on HP 50g - Gerald H - 01-14-2018 02:17 PM (01-14-2018 02:06 PM)Thomas Okken Wrote:(01-14-2018 01:59 PM)Gilles59 Wrote: -86 SF Gilles is correct, you must attach the built-in Development Lib, number 256. The additional functions in lib 256 are a boon for anyone programming 49G to 50g. RE: Programming Challenge: Palindromic Numbers on HP 50g - rprosperi - 01-14-2018 02:37 PM (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]). RE: Programming Challenge: Palindromic Numbers on HP 50g - Thomas Okken - 01-14-2018 02:46 PM 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! RE: Programming Challenge: Palindromic Numbers on HP 50g - Gilles59 - 01-14-2018 03:51 PM (01-14-2018 02:46 PM)Thomas Okken Wrote: ...find the EDIT command 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 RE: Programming Challenge: Palindromic Numbers on HP 50g - Gerald H - 01-14-2018 04:05 PM 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. RE: Programming Challenge: Palindromic Numbers on HP 50g - Gilles59 - 01-14-2018 04:10 PM (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 RE: Programming Challenge: Palindromic Numbers on HP 50g - Gerald H - 01-14-2018 04:10 PM The <= in the programme as depicted in the thread does not exist on 50g - correct form is ≤ Similarly >= is ≥ |