HP Forums
Challenge: First Digit of Factorial Programme - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: General Forum (/forum-4.html)
+--- Thread: Challenge: First Digit of Factorial Programme (/thread-9637.html)



Challenge: First Digit of Factorial Programme - Gerald H - 12-05-2017 08:11 AM

The challenge is to produce a programme that for natural number input N returns the first, ie leftmost, digit of N! on the 50g.

The programme below uses the formula here

http://mathworld.wolfram.com/StirlingsApproximation.html

& gives correct answers for input 0 to 5,362.

The OEIS reference is here

Edit: Was wrong link.

https://oeis.org/A008905

Speed is the secondary consideration & accuracy the first.

I don't expect my programme to be bettered but would be very pleased to be proven wrong.

Size: 76.

CkSum: # 86A4h

Code:
::
  CK1&Dispatch
  BINT1
  ::
    %>%%
    DUPDUP
    %%+
    %%3
    %%1/
    %%+
    %%PI
    %%*
    %%SQRT
    OVERDUP
    %%^
    ROT
    %%EXP
    %%/
    %%*
    %%.5
    %%+
    %%INT
    DO>STR
    BINT1
    BINT1
    SUB$
    FPTR2 ^S>Z
  ;
;