You need to add the trailing 'x' to the formatted number.
I'm unskillful in writing tacit form but the following seems implementing your logic.
      _5{. |. ": ". ,&'x' |. ": */ 1+i.10x
36288
      _5{. |. ": ". ,&'x' |. ": */ 1+i.20x
17664
   _5{. |. ": ". ,&'x' |. ": */ 1+i.10050x
69696

btw I think that ! should be more efficient than */@:>:@:i.

Geoff Canyon wrote:
I'm trying to find the last five non-zero digits of a large factorial. So for:

!10x = 3628800

the answer would be 36288 while for:

!20x = 2432902008176640000

the answer would be 17664.

I'm trying to do this by calculating /* 1+i.1000 without calculating large numbers by losing the trailing zeroes at each step and the leading digits more than five. Here's what I have so far:

(((|.&.":)@(5{.":&(|.&.":)))@*)/ 1+i.20x

The truncating code:

-- Converts to string, transposes, and converts back to a number. That loses trailing zeroes (because they're now leading zeroes). -- Converts to string and grabs the first five characters (which were the last five non-zero digits). -- Converts to string again -- not sure why this is necessary, but it doesn't work otherwise -- transposes, and converts back to a number.

This whole thing is performed atop *, and the resulting verb is inserted into the list from 1 to a large number.

This seems to work for large numbers up to 10049x. At 10050x I get an ill-formed number error.

Where did I go wrong?

regards,

Geoff
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to