HP Forums
(49G) Moser de Bruijn Sequence, OEIS A000695 - 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) Moser de Bruijn Sequence, OEIS A000695 (/thread-5040.html)



(49G) Moser de Bruijn Sequence, OEIS A000695 - Gerald H - 10-30-2015 05:36 PM

For integer input N the programme returns the Nth element of the sequence

http://oeis.org/A000695

ie the binary base representation of N read as a quaternary base number.

Code:

::
  CK1&Dispatch
  # FF
  ::
    FPTR2 ^DupQIsZero?
    ?SEMI
    Z0_
    SWAP
    FPTR2 ^Z>ZH
    FPTR2 ^ZBits
    ZERO_DO
    SWAP
    Z4_
    FPTR2 ^RMULText
    SWAP
    ISTOP-INDEX
    #1-
    FPTR2 ^ZBit?
    IT
    ::
      SWAP
      Z1_
      FPTR2 ^RADDext
      SWAP
    ;
    LOOP
    DROP
  ;
;