Post Reply 
(50g) OEIS A008904: Last Non-Zero Digit of Factorial
09-09-2017, 05:54 PM
Post: #1
(50g) OEIS A008904: Last Non-Zero Digit of Factorial
For input N , a natural number, the programme returns the Nth element in the series

https://oeis.org/A008904

NB This series does NOT become periodic.

Size: 228.5

CkSum: # 3597h

Code:
::
  CK1&Dispatch
  # FF
  ::
    '
    ::
      DUP
      ZINT 2
      Z<
      casedrop
      ZINT 1
      {
        ZINT 6
        ZINT 6
        ZINT 12
        ZINT 36
        ZINT 24
        ZINT 24
        ZINT 24
        ZINT 48
        ZINT 24
        ZINT 36
      }
      OVER
      ZINT 10
      FPTR2 ^ZMod
      FPTR2 ^Z2BIN
      #1+
      NTHCOMPDROP
      ZINT 3
      ROT
      ZINT 5
      FPTR2 ^ZQUOText
      DUP4UNROLL
      ZINT 4
      FPTR2 ^ZMod
      FPTR2 ^Z2BIN
      FPTR2 ^RP#
      FPTR2 ^RMULText
      SWAP
      1GETLAM
      EVAL
      FPTR2 ^RMULText
      ZINT 10
      FPTR2 ^ZMod
    ;
    1LAMBIND
    1GETLAM
    EVAL
    ABND
  ;
;
Find all posts by this user
Quote this message in a reply
09-11-2017, 08:54 PM
Post: #2
RE: (50g) OEIS A008904: Last Non-Zero Digit of Factorial
Here a smaller & much faster version of the programme:

Size: 185.5

CkSum: # E8F9h

Code:
::
  CK1&Dispatch
  # FF
  ::
    '
    ::
      DUP
      ZINT 2
      Z<
      casedrop
      BINT1
      {
        BINT6
        BINT6
        BINT12
        BINT36
        BINT24
        BINT24
        BINT24
        BINT48
        BINT24
        BINT36
      }
      OVER
      ZINT 10
      FPTR2 ^ZMod
      FPTR2 ^Z2BIN
      #1+
      NTHCOMPDROP
      {
        BINT1
        BINT3
        BINT9
        BINT27
      }
      ROT
      ZINT 5
      FPTR2 ^ZQUOText
      DUP4UNROLL
      ZINT 4
      FPTR2 ^ZMod
      FPTR2 ^Z2BIN
      #1+
      NTHCOMPDROP
      #*
      SWAP
      1GETLAM
      EVAL
      #*
      BINT10
      #/
      DROP
    ;
    DUP1LAMBIND
    EVAL
    ABND
    FPTR2 ^#>Z
  ;
;
Find all posts by this user
Quote this message in a reply
09-23-2017, 03:17 PM
Post: #3
RE: (50g) OEIS A008904: Last Non-Zero Digit of Factorial
A shorter & quicker programme:

Code:
::
  CK1&Dispatch
  # FF
  ::
    DUP
    Z2_
    Z<
    casedrop
    Z1_
    Z2_
    ZEROZERO
    4ROLL
    BEGIN
    Z5_
    FPTR2 ^ZDIVext
    FPTR2 ^Z>#
    DUP
    4ROLL
    DUP#1+
    5UNROLL
    #*
    SWAP
    BINT2
    #/
    SWAP
    #0=ITE
    #+
    DROP
    4ROLL
    #+
    UNROTDUP
    Z0_
    EQUAL
    UNTIL
    2DROP
    BINT4
    #/
    DROP
    FPTR2 ^RP#
    DUP
    Z1_
    EQUALNOT
    ?SEMI
    DROP
    Z6_
  ;
;
Find all posts by this user
Quote this message in a reply
Post Reply 




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