[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Factorial Elegance



abigail@foad.org wrote:
> 
> However, if you want a cute little function, that does factorials
> giving exact answers, no matter how large the argument is:
> 
>   sub factorial {local $" = "*"; my @a = (1, 1 .. shift); `echo '@a' | bc`}

Wow, that is cute!  (Hmm, is bc in the PPT?... Yep!)

Here it is using dc instead, which ought to be quicker since it
avoids one process invocation (bc runs dc).

  sub factorial {local $" = '*'; qx(echo '1 @{[1..shift,"p"]}' | dc)}

-- 
John Porter


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe