/**
  * ITERATIVE FACTORIAL CALCULATION
  * calculate n factorial. Only good for 0 <= n <= 20
  * Uses simple iterative for loop.
  * @author Roedy Green
  */
static long factorial ( int n )
   {
   if ( n < 0 || n > 20 )
      {
      throw new IllegalArgumentException( "factorial can only handle 0 <= n <= 20" );
      }
   if ( n == 0 )
      {
      return 1;
      }
   long result = n;
   for ( int i=n-1; i>1; i-- )
      {
      result *= i;
      }
   return result;
   }