(49G) OEIS A178225: Test for Binary-Palindromicity - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (49G) OEIS A178225: Test for Binary-Palindromicity (/thread-10221.html) |
(49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-22-2018 06:18 PM For integer decimal input N the programme tests whether N in binary is palindromic. This is OEIS https://oeis.org/A178225 Size: 95.5 CkSum: # C785h Code: :: RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-23-2018 03:02 PM A neater, faster programme: Size: 122.5 CkSum: # 1FA9h Code: :: RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-25-2018 09:43 AM Here the definitive version of the programme, a model of elegance, shortest & fastest possible. I'm sure no one can find an improvement - I'd be amazed if you did! Size: 105. CkSum: # 2C8Eh Code: :: RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Werner - 02-26-2018 08:12 AM Well.. that sounded like a challenge, no? Never could resist. Two things bothered me about your code: First, the sequence Code: BINT2 While #2/ is not the same, in this case it does the job - there's no need to test the middle bit, so to speak. Second thing: the snippet Code: ?SKIP The secondary wastes 5 bytes in my eyes ;-) so I tried to do without one. It turned out not to be so easy to improve upon, though. All I've been able to manage so far is save a single command (2.5 bytes). Well, this is it, 97.5 Bytes, # 945Fh Code: :: Cheers, Werner RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-26-2018 10:27 AM Very nice, Werner, congrats! After incorporating your suggestion not to test the middle bit into my version, my programme tested the 691 decimal digits binary palindrome 8999426634711432210874665907816903956988683664722921509315478192749207880463456922990872105835307171055080251964909961257453802179645499054716333672539545544118932968691884084960688692597413433759874480699854844501836094850133947983753204817698281788633116753054503696404359361578125612931539740671066508864784351529154391934339180653852887403515211867169617043784799543175497949666073579771413066215421083208629713930186272527242260162642480210729326691627240372999886606875669375524245678348406217132838891048302886533496403036545542639162038790659197087400238193942009504229380072518565320107237768892369217461716099224829006631795274618330918728005922738663971483339019497645460273904057 in 3.891345 s & your programme took 3.869235 s (average of 20 runs). So your programme is smaller & faster, I shall put it in my library. Thus the crestfallen boaster acknowledges your acumen. RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-26-2018 05:56 PM Shorter: Size: 92.5 CkSum: # 1249h Code: :: RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-26-2018 07:41 PM Shorter: NB PTR 273B6 has been stable at least from version 1.19-6 on. Size: 90. CkSum: # FB5Bd (edited to correct incorrect checksum) Code: :: RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Werner - 02-27-2018 09:01 AM But what does it do, PTR 273B6? Werner RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-27-2018 10:14 AM It puts the short form of ZINT 1 on the stack. RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Werner - 02-27-2018 10:57 AM In that case, add EQU ZINT_1 $273B6 as first line of your source code, then you can use ZINT_1. A bit clearer than PTR 273B6 ;-) Werner RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-27-2018 11:24 AM In my own programming environment I use an XTable library where Z1_ represents the pointer. As not everyone has the same XTable library I avoid using Z1_ publicly, preferring to use the pointer, which should compile OK for everyone. Your suggestion is a good idea, I mean more transparent, but could well confuse those not so experienced in Sys programming. RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Werner - 02-27-2018 01:15 PM "but could well confuse those not so experienced in Sys programming" ? More confused than by PTR 273B6? Werner |