Factorials and PHP


When it comes to factorials Mysql struggles. Really struggles. Nothing is impossible but it certainly isn't easy to calculate values larger than 50! with mysql. So how does it's good friend PHP fare? Amazingly well. Using the arbitrary precision math (BCMath) functions of PHP you can calculate factorials at the drop of a hat. It's blistering speed is a pleasent surprise.

Using the arbitary precision math library. You can solve problem 20 at project Euler in the blink of an eye. Here is the code.

comments powered by Disqus