Chris Angelico wrote:
Question: How many factorial functions are implemented because a program needs to know what n! is, and how many are implemented to demonstrate recursion (or to demonstrate the difference between iteration and recursion)? :)
A related question is how often factorial functions are even *used* in real code. I can think of two uses for factorials off the top of my head: * Coefficients of polynomials resulting from Taylor expansions. In that case you probably have a loop that's calculating the numerators and denominators iteratively, and the factorial is folded into that. Or you're looking up the coefficients in a table and not calculating factorials at all. * Combinations and permutations -- again, the factorials are probably folded into a loop that calculates the result in a more direct and efficient way. -- Greg -- http://mail.python.org/mailman/listinfo/python-list