HP Forums
(50G) Champernowne Sequence (OEIS A030190) - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (50G) Champernowne Sequence (OEIS A030190) (/thread-7536.html)



(50G) Champernowne Sequence (OEIS A030190) - Gerald H - 01-08-2017 09:35 AM

The Champernowne sequence

https://oeis.org/A030190

is the natural number sequence

https://en.wikipedia.org/wiki/ISO_80000-2

concatenated in binary & split into single digits:

0,1,1,0,1,1,1,0,0.........

For integer input N the programme returns the Nth element of the series starting from index zero.


Code:

::
  CK1&Dispatch
  BINT1
  ::
    FPTR2 ^PUSHFLAGS_
    %ABSCOERCE
    #1+
    DOBIN
    BINT64
    dostws
    BINT0
    BEGIN
    DUP
    #>HXS
    hxs>$
    LEN$
    #2-
    ROTSWAP
    2DUP
    #-
    4UNROLL
    DIFF_OR_ZERO_
    #0<>
    WHILE
    #1+
    REPEAT
    #>HXS
    hxs>$
    BINT3
    LAST$
    DUPLEN$
    FPTR2 ^POPFLAGS_
    ROTSWAP
    2DUP#>
    IT
    ::
      BINT0
      ROT
      #-SWAP
    ;
    SWAP#-
    DUP
    SUB$
    FPTR2 ^S>Z
  ;
;



RE: HP 50g: Champernowne Sequence (OEIS A030190) - Gerald H - 01-17-2017 08:25 AM

An alternative algorithm is used in the programme below, having LAMBW as a sub-programme.

LAMBW returns the Lambert w function for real input & can be found here

http://www.hpmuseum.org/forum/thread-7616.html

I would be grateful for improvements to the programme & notification of any aberrant results.

Code:

  CK1&Dispatch
  BINT1
  ::
    %2
    %LN
    %2
    %/
    OVER
    %1-
    %*
    xLAMBW
    %2
    %LN
    %/
    %1+
    %CEIL
    %2
    OVER
    %^
    DUP
    4PICK
    %+
    %2
    %-
    3PICK
    %MOD
    3PICK
    %-
    %1+
    %2
    SWAP
    %^
    4UNROLL
    ROT
    %+
    %1-
    SWAP
    %/
    %1-
    %CEIL
    %*
    %FLOOR
    %2
    %MOD
  ;
;