James Edward Gray II writes:
 > On Nov 26, 2003, at 1:35 AM, B. Rothstein wrote:
 > 
 > > Does anyone have any suggestions on how to create an array to hold the 
 > > value
 > > of 1000 factorial?
 > 
 > I'm afraid I don't understand your question.  An array holds multiple 
 > values, but 1,000 factorial is a single value.  You want an array to 
 > hold all the numbers used to calculate it?
 > 
 > my @factors = ( 1..1000 );
 > 
 > We could then calculate the answer with:
 > 
 > my $factorial = 1;
 > $factorial *= $_ foreach @factors;
 > 
 > It's probably easier to leave out to array though:
 > 
 > my $factorial = 1;
 > $factorial *= $_ foreach 1..1000;
 > 
 > Any of this helping you?
 > 
 > James

I think what he wants is an array to hold the first 1000 factorial
values.  Since 1000! is *REALLY* big, this would imply an infinite (or 
at least extended) precision integer arithmetic package, and an
implementation of an array of these big integer objects.

The array could then hold the values of (1! .. 1000!) so they would
not need to be recomputed every time they were needed.  An even better 
approach would be a lazy evaluator for the factorial function, so you
would not need to compute a value unless it was called for, but once
you had computed it, you would not need to re-compute it.

Alternatively, of course, if an approximate value is acceptable, the
values could be stored as an array of floating point numbers, but that 
is so simple that I think it is not what he wants.

Rj

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to