Left factorials,   !n,   may refer to either   subfactorials   or to   factorial sums;

the same notation can be confusingly seen being used for the two different definitions.

Sometimes,   subfactorials   (also known as derangements)   may use any of the notations:

     !n`   
     !n  
     n¡  


(It may not be visually obvious, but the last example uses an upside-down exclamation mark.)



This Rosetta Code task will be using this formula   (factorial sums)   for   left factorial:


   



!
n
=

∑

k
=
0


n
−
1


k
!


{\displaystyle !n=\sum _{k=0}^{n-1}k!}




 where


   



!
0
=
0


{\displaystyle !0=0}






Task
Display the left factorials for:

   zero through ten     (inclusive)
   20   through   110   (inclusive)   by tens


Display the length (in decimal digits) of the left factorials for:

   1,000   through   10,000   (inclusive), by thousands.


Also see

   The OEIS entry: A003422 left factorials
   The MathWorld entry: left factorial
   The MathWorld entry: factorial sums
   The MathWorld entry: subfactorial


Related task

   permutations/derangements (subfactorials)


$ include "seed7_05.s7i";
  include "bigint.s7i";
 
const func bigInteger: leftFact (in integer: n) is func
  result
    var bigInteger: leftFact is 0_;
  local
    var bigInteger: factorial is 1_;
    var integer: i is 0;
  begin
    for i range 1 to n do
      leftFact +:= factorial;
      factorial *:= bigInteger conv i;
    end for;
  end func;
 
const proc: main is func
  local
    var integer: n is 0;
  begin
    writeln("First 11 left factorials:");
    for n range 0 to 10 do
      write(" " <& leftFact(n));
    end for;
    writeln;
    writeln("20 through 110 (inclusive) by tens:");
    for n range 20 to 110 step 10 do
      writeln(leftFact(n));
    end for;
    writeln;
    writeln("Digits in 1,000 through 10,000 by thousands:");
    for n range 1000 to 10000 step 1000 do
      writeln(length(str(leftFact(n))));
    end for;
    writeln;
  end func;