HP Forums
(49G) Finds Binary Palindrome's Position in OEIS A057148 - 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) Finds Binary Palindrome's Position in OEIS A057148 (/thread-10189.html)



(49G) Finds Binary Palindrome's Position in OEIS A057148 - Gerald H - 02-17-2018 09:10 PM

For binary integer input B the programme returns B's position in the sequence

https://oeis.org/A057148

eg For input

1000101010101010001

the programme returns

1066.

Size: 158.5

CkSum: # EC76h

Code:
::
  CK1&Dispatch
  # FF
  ::
    DUP
    ZINT 2
    Z<
    case
    ::
      ZINT 1
      FPTR2 ^QAdd
    ;
    FPTR2 ^Z>S
    DUPLEN$
    BINT2
    #/
    SWAP
    #0=ITE
    ::
      ONESWAP
      SUB$
      "1"
    ;
    ::
      #1+
      ONESWAP
      SUB$
      CDR$
      "10"
    ;
    SWAP&$
    ZINT 0
    OVERLEN$
    #1+_ONE_DO
    DUP
    FPTR2 ^QAdd
    OVERINDEX@
    SUB$1#
    BINT48
    #=ITE
    ZINT 0
    ZINT 1
    FPTR2 ^QAdd
    LOOP
    SWAPDROP
  ;
;