HP Forums
(49G) A Fibonacci-like Sequence with Only Composite Members - 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) A Fibonacci-like Sequence with Only Composite Members (/thread-4331.html)



(49G) A Fibonacci-like Sequence with Only Composite Members - Gerald H - 07-09-2015 05:10 PM

A programme to produce a Fibonacci-like sequence but starting with zeroth element

106276436867

& first element

35256392432

the following numbers being the sum of the preceding two elements of the series.

Interestingly, every element of the series is a composite number.

Input an integer N to find the Nth sequence element.
Code:

::
  CK1&Dispatch
  BINT1
  ::
    %ABSCOERCE
    ZINT 106276436867
    SWAP
    DUP#0=csDROP
    ZINT 35256392432
    SWAPDUP
    #1=case
    DROPSWAPDROP
    FPTR2 ^#>Z
    ::
      DUP
      Z2_
      Z<
      case
      ::
        BINT4
        NDUPN
        DROP
      ;
      FPTR2 ^Z>ZH
      Z-2_
      Z0Z1_
      4PICK
      FPTR2 ^ZBits
      SWAPDROP#1-_
      ZERO_DO
      FPTR2 ^ZSQ_
      SWAP
      FPTR2 ^ZSQ_
      2DUP
      FPTR2 ^RSUBext
      DUP
      FPTR2 ^RADDext
      3PICK
      FPTR2 ^RADDext
      3UNROLL
      FPTR2 ^RADDext
      SWAPROT
      FPTR2 ^RADDext
      3PICK
      ISTOP-INDEX
      #1-
      FPTR2 ^ZBit?
      SWAPDROP
      ITE
      ::
        DUPUNROT
        FPTR2 ^QAdd
        Z-2_
      ;
      Z2_
      3UNROLL
      LOOP
    ;
    2SWAP
    2DROP
    ROT
    FPTR2 ^RMULText
    3UNROLL
    FPTR2 ^RMULText
    FPTR2 ^RADDext
  ;
;