(49G) OEIS A178225: Test for Binary-Palindromicity

+- HP Forums (http://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-25-2018 03:43 AM

For integer decimal input N the programme tests whether N in binary is palindromic.

This is OEIS

https://oeis.org/A178225

Size: 122.5

CkSum: # 1FA9h

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:
::
  CK1&Dispatch
  # FF
  ::
    %1
    SWAPDUP
    ZINT 2
    Z<
    caseDROP
    FPTR2 ^Z>ZH
    FPTR2 ^ZBits
    DUPUNROT
    BINT2
    #/
    #+
    ZERO_DO
    SWAP#1-SWAP
    OVER
    FPTR2 ^ZBit?
    SWAPINDEX@
    FPTR2 ^ZBit?
    ROT
    EQUAL
    ?SKIP
    ::
      ROTDROP
      %0
      3UNROLL
      ExitAtLOOP
    ;
    LOOP
    2DROP
  ;
;



RE: (49G) OEIS A178225: Test for Binary-Palindromicity - Gerald H - 02-26-2018 01: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:
::
  CK1&Dispatch
  # FF
  ::
    PTR 273B6
    FPTR2 ^ZNMax
    FPTR2 ^Z>ZH
    FPTR2 ^ZBits
    DUPUNROT
    #2/
    DUP
    ZERO_DO
    DROP
    SWAP#1-SWAP
    OVER
    FPTR2 ^ZBit?
    SWAPINDEX@
    FPTR2 ^ZBit?
    ROT
    EQUAL
    DUP
    ?SKIP
    ExitAtLOOP
    LOOP
    ROTROT2DROP
    COERCEFLAG
  ;
;