Post Reply 
(49G) Golomb Sequence
08-28-2015, 04:05 PM (This post was last modified: 06-15-2017 01:47 PM by Gene.)
Post: #1
(49G) Golomb Sequence
Golomb's sequence: 1, 2, 2, 3, 3, 4, 4 ... consists of elements indicating the number of occurences of its index in the list, index commencing at 1.

The programme gives exact correct integers for indices to 10^12, thereafter approximate.

Enter integer index to return the number of its appearances in the sequence.

Code:

::
  CK1&Dispatch
  # FF
  ::
    '
    ::
      DUP
      % .618322
      %^
      % 1.2
      %*
      % .513
      %+
      %IP
      {
        % 423.
        % 507.
        % 597.
        % 709.
        % 828.
        % 954.
      }
      ROT
      EQUALPOSCOMP
      #0=?SEMI
      %1+
    ;
    SWAP
    FPTR2 ^Z>R
    %ABS
    DUP
    % 999999999999.
    %>
    case
    ::
      SWAP
      EVAL
    ;
    DUP
    % 1087.
    %<
    ITE
    ::
      SWAP
      EVAL
    ;
    ::
      %1
      DUP
      DUPDUP
      4NULLLAM{}
      BIND
      %1-
      BEGIN
      1GETLAM
      4GETLAM
      %1+
      DUP4PUTLAM
      4PICK
      EVAL
      DUP
      3PUTLAM
      %.5
      DUPUNROT
      %*
      %+
      %+
      3GETLAM
      DUP
      1GETLAM
      %+
      1PUTLAM
      4GETLAM
      %*
      DUP
      2GETLAM
      %+
      2PUTLAM
      %*
      OVERUNROT
      %-
      DUP
      %0>
      WHILE
      SWAPDROP
      REPEAT
      ROTDROP
      3GETLAM
      DUP
      %CHS
      1GETLAM
      %+
      1PUTLAM
      4GETLAM
      %*
      DUP
      %CHS
      2GETLAM
      %+
      2PUTLAM
      SWAPDROPSWAP
      BEGIN
      DUP
      1GETLAM
      %1+
      DUP1PUTLAM_
      4GETLAM
      DUP
      2GETLAM
      %+
      2PUTLAM
      %*
      %-
      DUP
      %0>
      WHILE
      SWAPDROP
      REPEAT
      DROPSWAPDROP
      1GETLAM
      DUPUNROT
      %+
      %1-
      SWAP
      %/
      %IP
      2GETLAM
      %+
      4GETLAM
      ABND
      %-
    ;
    FPTR2 ^R>Z
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)