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)


( ( leftFact
  =   result factorial i
    .   0:?result
      & 1:?factorial
      & 0:?i
      &   whl
        ' ( !i+1:~>!arg:?i
          & !factorial+!result:?result
          & !factorial*!i:?factorial
          )
      & !result
  )
& ( iterate
  =   from to step c fun
    .   !arg:(?from.?to.?step.?fun)
      & !from+-1*!step:?from
      & !step:?c
      &   whl
        ' ( !step+!from:~>!to:?from
          & !fun$(leftFact$!from)
          )
      & 
  )
& out$"First 11 left factorials:"
& iterate$(0.10.1.out)
& out$"
20 through 110 (inclusive) by tens:"
& iterate$(20.110.10.out)
& out$"
Digits in 1,000 through 10,000 by thousands:"
&   iterate
  $ ( 1000
    . 10000
    . 1000
    . (=L.@(!arg:? [?L)&out$!L)
    )
)