develooper Front page | | Postings from August 2002

Factorial and large numbers.

Thread Next
Tor Hildrum
August 8, 2002 11:04
Factorial and large numbers.
Message ID:
Could someone annotate some of the various working solutions, emphasizing
how they work around the problem with large numbers?

I was able to make solutions that worked for n! where n < 25.
But, at 25! the numbers got to large. I tried regex'ing the last zeroes,
without success. I was still loosing digits.

-p $v=$_;for($_=1;$v>0;){$_*=$v--}s/0//g;$_=chop."\n"

My shortest solution, but still in the sandtrap.
I'm basically just counting down 'n' with $_*=$v--;
n=9 => 9*8*7*6*5*4*3*2*1
But, at 25!, the numbers are getting to big, so it's not accurate enough.
I tried with:
-p $v=$_;for($_=1;$v>0;){$_*=$v--;s/0*$//}s/0//g;$_=chop."\n"
But, that didn't help much.

I also hate $_=chop."\n", but couldn't figure out anything else.

What does $`%9e9 do?

Couldn't even get a working solution on my virgin hole :)


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About