[Question]
  [
The alternating factorial is an alternating sum of decreasing factorials. For example, we could calculate the alternating factorial of 4 as follows:
* First, calculate the factorials from 4 down to 1:
$$
4!\quad3!\quad2!\quad1!\quad = \\
4\cdot3\cdot2\cdot1\qquad3\cdot2\cdot1\qquad2\cdot1\qquad1\quad= \\
24\quad6\quad2\quad1
$$
* Next, insert alternating signs between the products, always starting with \$\;-\$.
$$
24-6+2-1 = \\
19
$$
So 19 is the alternating factorial of 4. Mathematically, the alternating factorial is defined as
$$
\large\operatorname{af}(n) = \sum\_{i=1}^n(-1)^{n-i}i!
$$
For example,
$$
\operatorname{af}(4)=(-1)^3\times1!+(-1)^2\times2!+(-1)^1\times3!+(-1)^0\times4!=19
$$
The alternating factorial can also be calculated by the recurrence relation
$$
\operatorname{af}(n) =
\begin{cases}
0, & \text{if $\;n=0$} \\
n!-\operatorname{af}(n-1), & \text{if $\;n>0$}
\end{cases}
$$
The sequence of alternating factorials is [OEIS A005165](https://oeis.org/A005165).
## Task
Given a non-negative integer as input, output its alternating factorial. You don't need to worry about values exceeding your language's integer limit. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the code with the fewest bytes (in each language) wins.
## Test cases
```
n   af(n)
0   0
1   1
2   1
3   5
4   19
5   101
6   619
7   4421
8   35899
9   326981
```
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
R!ḅ-
```
A monadic Link that accepts a non-negative integer, \$n\$, and yields its alternating factorial.
**[Try it online!](https://tio.run/##ASUA2v9qZWxsef//UiHhuIUt/8W7wrUsw4dq4oCcID0@IOKAnSlZ//85 "Jelly – Try It Online")**
### How?
```
R!ḅ- - Link: n
R    - range (n) -> [1, ..., n-1, n]
 !   - factorial -> [1!, ..., (n-1)!, n!]
   - - -1
  ḅ  - convert from base -1 -> n! - (n-1)! + ... [+/-] 1!
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 20 bytes
```
AlternatingFactorial
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2ar8N8xpyS1KA/Iz0t3S0wuyS/KTMz5H1CUmVcSnRZtGRv7HwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 6 bytes [SBCS](https://github.com/abrudz/SBCS)
```
¯1⊥∘!⍳
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=O7Te8FHX0kcdMxQf9W4GAA&f=Szu04lHvZksA&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
[Answer]
# [Desmos](https://desmos.com/calculator), 28 bytes
```
f(k)=∑_{n=1}^k(-1)^{k-n}n!
```
[Try It On Desmos!](https://www.desmos.com/calculator/biwt3b1goj)
Yea, I really could not think of any golfier way than to just copy the formula provided in the question. Not the most creative answer out there but at least it's the golfiest in Desmos (at least it better be....).
[Answer]
# [><> (Fish)](https://esolangs.org/wiki/Fish), ~~53~~ 42 bytes
```
i:?vl1=?n-30.
:?v\:1$:@*$1-
1.\6
00.\~~$1-
```
[Try it](https://mousetail.github.io/Fish/#eyJ0ZXh0IjoiaTo/dmwxPT9uLTMwLlxuOj92XFw6MSQ6QCokMS1cbjEuXFw2XG4wMC5cXH5+JDEtIiwiaW5wdXQiOiI3Iiwic3RhY2siOiIiLCJzdGFja19mb3JtYXQiOiJudW1iZXJzIiwiaW5wdXRfZm9ybWF0IjoibnVtYmVycyJ9)
The bottom 3 lines calculate the factorial of a number and push it to the stack, the top line just subtracts the top 2 elements from the stack, and prints the top of the stack if there is just one.
After a number is printed, the `-` crashes and the program exits.
[![enter image description here](https://i.stack.imgur.com/b1oHS.png)](https://i.stack.imgur.com/b1oHS.png)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 20 bytes
```
Nest[++i!-#&,i=0,#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73y@1uCRaWztTUVdZTSfT1kBHOVbtf0BRZl5JtLKuXZoDkFsXnJyYVxeUmJeeGm2gYxn7HwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [Python](https://www.python.org), 40 bytes
```
f=lambda n:n>1and~-n*f(n-1)+n*f(n-2)or n
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72soLIkIz9vwYKlpSVpuhY3NdJscxJzk1ISFfKs8uwME_NS6nTztNI08nQNNbUhDCPN_CKFPKh67TQQRyEzT6EoMS89VcPQQNOqoCgzr0RDSTXFSkE1RUlVI08HqE1TUxOiBWYVAA)
Port of @Arnauld's JS answer.
[Answer]
# JavaScript (ES6), 28 bytes
```
f=n=>n<2?n:n*f(n-2)+--n*f(n)
```
[Try it online!](https://tio.run/##HYsxDoMwEAR7XnEFhQ/LKFAGTL6CBThKhPaQQTSW3@5Aqpli5utOt0/hsx0GMi85ews7oG9feKLyCqZlbcxfOXsJCmTp0RGop@am1kyxIJoEu6xLvcpbjU6VEYmvtIz3mUbuipR/ "JavaScript (Node.js) – Try It Online")
This is based on the recurrence formula given on [OEIS](https://oeis.org/A005165) for \$n > 1\$:
$$a(n) = n\times a(n-2) + (n-1)\times a(n-1)$$
This alternate form accepts either Numbers or Bigints as input:
```
f=n=>n<2?n:n--*f(~-n)+n*f(n)
```
[Try it online!](https://tio.run/##HcsxDoMwEAXRnlNsQeHFMkKhCzi5ChbBCIT@IkBpLOfqhtC9YmZ2X7f327QeBvIZUvIW9oX28cYTxhRe/QxY4wI4edkUyFKFhkAt1Te0ZgoZUS/YZRnKRUbVOZUHRL7iPPzf2HGTxXQC "JavaScript (Node.js) – Try It Online")
[Answer]
# [Curry (PAKCS)](https://www.informatik.uni-kiel.de/%7Epakcs/), 48 bytes
```
f 0=1
f x|x>0=x*f(x-1)
g 0=0
g x|x>0=f(x)-g(x-1)
```
[Try it online!](https://tio.run/##Sy4tKqrULUjMTi7@/z9NwcDWkCtNoaKmws7AtkIrTaNC11CTKx0obAAkIcJAQU3ddLDM/9zEzDwFW4XcxAKFdIVoAwU9PQXL2P8A "Curry (PAKCS) – Try It Online")
My first answer in Curry.
I had to determine the factorial because I couldn’t find it in the standard library
[Answer]
# [R](https://www.r-project.org), ~~29~~ 31 bytes
*Edit: +2 bytes and complete change of approach to fix bug spotted by pajonk*
```
\(x)Reduce(`-`,gamma(x:1+1),,T)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMGKxJyStMTkEtulpSVpuhb7YzQqNINSU0qTUzUSdBN00hNzcxM1KqwMtQ01dXRCNCGqthQnFhTkVGoYWhka6EANgEotWAChAQ)
[Answer]
# [Thunno 2](https://github.com/Thunno/Thunno2), 6 [bytes](https://github.com/Thunno/Thunno2/blob/main/docs/codepage.md "Thunno 2 Codepage")
```
RR€puḋ
```
(Thunno 2 isn't on ATO yet)
It seems that I forgot to add a "factorial" built-in to Thunno 2...
Port of Jonathan Allan's Jelly answer.
#### Explanation
```
RR€puḋ  # Implicit input                              5
R       # Push the range [1..input]                   [1, 2, 3, 4, 5]
 R      # For each number in this, push its range     [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4], [1, 2, 3, 4, 5]]
  €p    # Product of each inner list                  [1, 2, 6, 24, 120]
    uḋ  # Convert from base -1                        101
        # Implicit output
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 7 bytes
```
:Yp-1ZQ
```
[Try it online!](https://tio.run/##y00syfn/3yqyQNcwKvD/f1MA "MATL – Try It Online")
[Answer]
# [Oasis](https://github.com/Adriandmen/Oasis), 4 bytes
```
n!-0
```
[Try it online.](https://tio.run/##y08sziz@/z9PUdfg////lgA)
**Explanation:**
```
   0 # Start with a(0)=0 (Oasis programs implicitly start with a(0)=1 unfortunately)
     # And calculate every following a(n) by:
  -  #  Subtracting
     #  the implicit previous term a(n-1)
n!   #  from n!
     # (and output the a(implicit input-argument)'th term implicitly as result)
```
[Answer]
# [Nibbles](http://golfscript.com/nibbles/index.html), ~~5.5~~ 5 bytes (10 nibbles)
*Edit: -0.5 bytes (1 nibble) thanks to xigoi*
```
/.\,$`*,$-
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m708LzMpKSe1eMGCpaUlaboWq_T1YnRUErR0VHQhAlDxBesNuAy5jLiMuUy4TLnMuMwhwgA)
Port of [my R answer](https://codegolf.stackexchange.com/a/260148/95126).
```
/.\,$`/,$*-
 .          # map over
  \         # reverse of 
   ,$       # 1..input:
     `*     #   product of
       ,$   #   1..each element
            # (at this point we have list of
            # factorials in reverse order);
/           # now, fold over this from right to left
         -  # by subtraction
```
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 64 bytes
```
{(({})[()]<({([{}]()({}))([{}]({}))}{}{}([{}])((){}))>)}{}({}<>)
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/v1pDo7pWM1pDM9ZGo1ojuro2VkMTJKIJYYNYtdVACOZqamhogkTsQGJAORs7zf//LQA "Brain-Flak – Try It Online")
This does not compute any factorials as intermediate results. Instead, it multiplies by successively smaller numbers and either adds or subtracts one. Sample calculation for the alternating factorial of 5:
```
0  *6 +1 = 1
1  *5 -1 = 4
4  *4 +1 = 17
17 *3 -1 = 50
50 *2 +1 = 101
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
R!_@ƒ0
```
[Try it online!](https://tio.run/##y0rNyan8/z9IMd7h2CSD/0d36xxuV3nUtMb9/39LAA "Jelly – Try It Online")
## How it works
```
R!_@ƒ0 - Main link. Takes n on the left
R      - Range; [1, 2, ..., n]
 !     - Factorial; [1, 2, 6, ..., n!]
    ƒ0 - Reduce by the following, beginning with 0:
  _@   -   y - x
```
For a list `[a, b, c, d, e]`, `_@ƒ0` calculates
```
((((0 _@ a) _@ b) _@ c) _@ d) _@ e
= e _ (d _ (c _ (b _ (a _ 0))))
= e - d + c - b + a - 0
```
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
ɾ¡uβ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyJ+IiwiIiwiyb7CoXXOsiIsIiIsIiEoXFxkKykgKyhcXGQrKVxuMCAgIDBcbjEgICAxXG4yICAgMVxuMyAgIDVcbjQgICAxOVxuNSAgIDEwMVxuNiAgIDYxOVxuNyAgIDQ0MjFcbjggICAzNTg5OVxuOSAgIDMyNjk4MSJd)
Port of the 4 byte jelly answer
## Explained
```
ɾ¡uβ 
ɾ    # range [1, n]
 ¡   # factorial of each
  uβ # converted from base -1
```
[Answer]
# [Pyt](https://github.com/mudkip201/pyt), 10 bytes
```
řĐ1~⇹^⇹!·Å
```
[Try it online!](https://tio.run/##K6gs@f//6MwjEwzrHrXvjANixUPbD7f@/28GAA "Pyt – Try It Online")
```
ř                 implicit input (n); řangify [1,2,...,n]
 Đ                Đuplicate 
  1~              -1
    ⇹             swap top two elements
     ^            -1^[1,2,3,...,n]
      ⇹           swap top two elements
       !          factorial [1!,2!,3!,...,n!]
        ·         dot product
         Å        Åbsolute value; implicit print
```
Uses that fact that \$\text{af}(n)=\left|\sum\_{i=1}^n(-1)^i i!\right|\$
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 54 bytes
```
~(`.+
.+¶$$.($$'$&*
+`_(_(_+))
$$($.&$*$2$.1$*$1)
__
_
```
[Try it online!](https://tio.run/##DcW7DYAgFAXQ/s5xxQckL4L/CRwDLCxsLIy1YzmAi6E5xTm3az/WUCpZcrklq4f69yFVyJrGweckP28tSKEaOkZq@AsWKSGV0iAgokWHHgNGTJg/ "Retina – Try It Online") Link includes test cases. Explanation: Port of @Arnauld's JavaScript answer.
```
~(`
```
Run the output of the rest of the program on the original input.
```
.+
.+¶$$.($$'$&*
```
Convert the input to unary and replace it with a command that replaces the input with an expression that converts the literal unary string back to decimal. The unary string represents `f(n)` at this point.
```
+`_(_(_+))
$$($.&$*$2$.1$*$1)
```
For `n>2`, repeatedly apply the recurrence relation `f(n)=n*f(n-2)+(n-1)*f(n-1)` to the unary string. `n` and `(n-1)` are represented in decimal while `f(n-2)` and `f(n-1)` remain represented in unary for the next pass.
```
__
_
```
`f(2)=1` while `f(n)=n` for `n<2` which is already correct.
Example: if `n=7`, then the rest of the program produces the following output:
```
.+
$.($'$(7*$(5*$(3*_2*_)4*$(4*_3*$(3*_2*_)))6*$(6*$(4*_3*$(3*_2*_))5*$(5*$(3*_2*_)4*$(4*_3*$(3*_2*_)))))
```
Retina will evaluate the expression using big integers so the limit is the length of the generated expression which has to fit in memory.
Note that there's an extra `$'` in the final expression in case it is empty to work around a Retina bug whereby `$.()` crashes Retina when it has no elements, but it's fine if it has a non-zero number of empty elements.
The recurrence relation is not used for `f(2)` because that would invoke `f(0)` whose representation would be empty, but `*` defaults to a RHS of `_` i.e. `1`. It could be done by representing `f(n)` with `$(n)` except that this triggers the empty length bug, so it needs another 3 bytes for a second copy of the workaround, making it overall a byte longer:
```
.+
.+¶$$.($$'$&*
~)+`_(_(_*))
$.&$*$$($$'$2)$.1$*$$($1)
```
[Answer]
# Excel, 38 bytes
Defined Name `a`:
```
=LAMBDA(n,IF(n,FACT(n)-a(n-1),))
```
After which, within the worksheet:
```
=a(A1)
```
for an input in cell `A1`.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), 4 [bytes](https://en.wikipedia.org/wiki/ISO/IEC_8859-1)
```
õÊìJ
```
[Try it](https://petershaggynoble.github.io/Japt-Interpreter/?v=1.4.6&code=9crsSg&input=NQ)
```
õÊìJ     :Implicit input of integer U
õ        :Range [1,U]
 Ê       :Factorials
  ì      :Convert from base
   J     :-1
```
[Answer]
# [Brachylog](https://github.com/JCumin/Brachylog), 11 bytes
```
0|-₁↰I&ḟ;I-
```
[Try it online!](https://tio.run/##SypKTM6ozMlPN/r/36BG91FT46O2DZ5qD3fMt/bU/f/f8n8UAA "Brachylog – Try It Online")
### Explanation
Uses the recurrence relation.
```
0             af(0) = 0
 |            Or
  -₁↰I        I = af(Input - 1)
      &ḟ;I-   Output = Input! - I
```
[Answer]
# [Julia 0.7](http://julialang.org/), 23 bytes
```
!n=n>0?prod(1:n)-!~-n:0
```
[Try it online!](https://tio.run/##yyrNyUw0//9fMc82z87AvqAoP0XD0CpPU1exTjfPyuC/g55CQVFmXklOnoaihoGVpabmfwA "Julia 0.7 – Try It Online")
Uses the recursive formula.
[Answer]
# [Pip](https://github.com/dloscutoff/pip), ~~17 16~~ 12 bytes
```
$* *\,\,aFDv
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgwYKlpSVpuhZrVLQUtGJ0YnQS3VzKIEJQmcXRFrFQJgA)
Port of Jonathan Allan's Jelly answer.
*-4 thanks to @DLosc*
#### Explanation
```
$* *\,\,aFDv   ; Input on command line
      \,a      ; Range from 1 to input
    \,         ; Range from 1 to each
$* *           ; Product of each inner list
         FDv   ; From a list of digits in base -1
               ; Implicit output
```
Old:
```
({$*\,a}M\,a)FDv   ; Input on command line
         \,a       ; Range from 1 to input
 {     }M          ; Map over this list:
  $*               ;   Product of...
    \,a            ;   ...range from 1 to the number
(           )FD    ; Convert from a list of digits...
               v   ; ...in base -1
                   ; Implicit output
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 12 bytes
```
Ｉ↨ＥＮΠ…¹⁺²ι±¹
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iOSOxKDk_MWfBgqWlJWm6FjcDAooy80o0nBOLSzScEotTNXwTCzQ88wpKS_xKc5NSizQ0dRQCivJTSpNLNIIS89JTNQyBAjmlxRpGOgqZmkCgo-CXmp5YApQA8ayXFCclF0NNXx6tpFuWoxS70BzCBwA) Link is to verbose version of code. Explanation:
```
   Ｎ            First input as a number
  Ｅ             Map over implicit range
     …          Range from
      ¹         Literal integer `1` to
         ι      Current value
       ⁺        Plus
        ²       Literal integer `2`
    Π           Take the product
 ↨        ±¹    Interpret as base `-1`
Ｉ               Cast to string
                Implicitly print
```
[Answer]
# [J](https://www.jsoftware.com), 10 bytes
```
_1#.1!@+i.
```
Port of [Jonathan Allan's](https://codegolf.stackexchange.com/users/53748/jonathan-allan) smart Jelly answer.
[Attempt This Online!](https://ato.pxeger.com/run?1=m70wa8FOJT31NAVbKwV1BR0FAwUrINbVU3AO8nFbWlqSpmuxKt5QWc9Q0UE7Uw8isFGTKzU5I19JWyFNzU4hU8_QACK-YAGEBgA)
```
_1#.1!@+i.
        i.  NB. range [0,n)
    1  +    NB. vectorized increment
     !@     NB. factorial of each
_1#.        NB. convert from base -1
```
[Answer]
# [minigolf](https://github.com/jfioasd/minigolf), ~~23~~ 22 bytes
```
Ti,n;o,T*:1n,n*_*;+s,_
```
[Attempt This Online!](https://ato.pxeger.com/run?1=3VjJkts2EK3KIQflmB9AOAeTI4oR5W2iqXGVE2df7CSTVZlSYUhIwpgiGQCUR_6VXJxD8gn5GH9NusFdBDm2K6ewVCWS6H69N5r44-90rzZJ_OLlW-_wbZoIReRejopbKtYpFZKNRvpPkLPqlfdQrLMti9UTvWKHTAaCp4on8Zm15TFfJ9HKckZHJGf1aBguacFj31rxiN1yYbXvUvuUgTiphFNKP4CY7ADAxEoD1AKYLakSwZZKZMwyk25YlCLhE8FjRUq1yY4JiRD2KhEk2LDgKY_X5OH5Y5KlIVVMOlavVsF_p9XjTKWZIhGXiiQrEiQhSxNQVBIKP_QNqIWagHgJDIVC-g9Vkjas8RXGTHq7uZaVoqW2tZt6t4ET37BrruwpUCI-irWs0V-ZWk1O_jnnbnyauOfHcz924-Pl8elYust88eW7byOlVDR4ClyLCxAVg7qyesA7G7LJkyrksScYDW1nbP0WW44n0wik6vsROpkTHsNPLuYT_yLXFBSPWGxzhzwg03nlqCATmIdsRyNYq14DNaaMjcsOOdOZM295N9fOo2nK4tBGp9pbmtqJCF0N6jg1GoskG-LW9A2DNVr-VL1e8vAalqajUchWeWxsdPFcJzWZPNBcuRTBZBap3HP4rF0SXru5X1gMySUg7zS_M28azdFW69SakyOgC5fA2dJbsW1a45bXsw3UXyF1AR4n7wGIa8076Viy56RemqS2c0HG-n2LOAKqJlFrsVgonLeISoQDh4MJidowMcBbRFwwlYm4WMsdvIqoUpAv1BlwKXqTzjtJw3XG1OFoyybjswqdD-XIq6q6W8psWymqxL6GKajz9aI8A5aqDkWVvxrMpZC8Gltk4AKwQxO4BBvOrBBUe6Bpp8EHEAdAJlGStGMMuUb4wp-3c0npDNF9oDf03QwsxQK3g9nXFMxosOlmohYjaLxmtg-FAV0MXo19NLxJh1bGSwoywVKg6OY0uoi7OZHTXW0FsWHWgZx8pSDLmRoULKpqc65rM8zSfnb9gHVoRpAaQT6jBgjkcsvb2UUZCbx3awoj7LGG3WYReb_Mb2OIau2aGaI7KLQxI2vHwrJ-mv48cKjWrClwZhCoA49SdyyAbZQ_Zx251CWX7YR0e7NTB7ybnHhV1XLZzSDNVtU5ZCInx4Q6Xex2knQMznseIlR2UUC6HMZBgQ2DgKHHq41Yj3WsYVSBWEO_eJM4H7J19Mrb2v8xwrBd0TcJ7jBLM4ZjYu40jRDGOoQ4ecCgicpjmyQc9lGI6ay_ucRmOK7hBPs9YzBexuxaETvYBxEPnHzYaSHCzixImskNmfh67EAKwiWBXVztvcN80oNbPg6hsOkNnpj4zis4bx0llzQi9XR1U5kg3aImv-iGsDGpwSbvd9dXTRJM1dowc9Iczn4Gz59pz5fpjV8WEAQK8_B-qCz7a2UOTQNWLuuKkR3VKoa8mp_zlKhniX6SRCVr1pm78HrtQmPl9G9wpDaGmowoOwxo5RmdqivVJVdYrEBko149_i_UqGbNK_CRIfBV763d2C95oEcciMv3ArCQHvY-vA5Hhhv3gzKyr7cfnJ3dsCGAOdbUn92-c_fe_ZMPdDbq0gaVUkghvmMk5Guu-nuKtrP1vVQBP_zwo0cff_LpZxrWn0JY_fv9QEAwbvB4K64nZyPy5198-dXX3zx-8u13359r9Ik_A_iJ3w-PFOMDzl4ZWJs_aOCpd7cfExaNrD9q1tnde_2ssGhk_alw1nTIUVMj688F6-zOEO_sjpH5l5x5djLAOzsxsv5aqjysM54r4Lxdf_56gqURDZhtJZYL0_GRdGO5dE-twwKsCZdIOD0djwdojpDG9U-BxmmcegT6ozI_R8nPSyRZiWRrOFTJv9YMH4zaplf_aKzWF9N2y34An2KPup0RJOJ3XDEhQ-F3O9F1_wCjeyLv2YsKTa56NG2J6ByMBBvhXjmGoRYv8w7dAQMMkG7YKEoCPAHyrsD_WmREt5chJcncKl4msOFcH-pgll1DNgDRBnDo4MmOaCpbtoXyWEuMRsWJWUtRSCVXkwB0fhz24s_b-c2_)
## Explanation
```
T            Push -1 (b)
i,n;         [1..n] range of input
o            Reverse it
,            Map in [n..1]:
  T*:          Multiply (b) by -1 (since -1^0 = 1
  1            Push 1
  n            Push curr. item
  ,n*_         Reduce 1..n by product
  *            mul. w/ b
;            End map
+            sum (works for 0 case since sum of [] is 0)
s,_          drop b
implicit output
```
[Answer]
# [PARI/GP](http://pari.math.u-bordeaux.fr/), ~~40~~ 35 bytes
saved 5 bytes thanks to the comment.
[Try it online!](https://tio.run/##K0gsytRNL/j/P00jT9M2MalYo7g0VyPX1lAnT6egKD9FIxvIzNXRzdbU1PxfUJSZV6KRpmEJZAMA)
```
f(n)=abs(sum(m=1,n,prod(k=1,m,-k)))
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 32 bytes
```
f(n){n=n<2?n:n*f(n-2)+f(--n)*n;}
```
[Try it online!](https://tio.run/##VVDbboMwDH3vV1hIlcJNo1CqMsr2MO0rBg8oJB3aZiqSaWiIXx8zGdA1io@OT2zLJ9w/cz6OkqHdY4an8BHv0aHUD21XMt9H28F0GGvU8FHWyGzoN0BnEkR3EVyL6qWADPrAg525MWFCERA/TGy/D4lG8TGhJAoPyXE3pGYKb1Bp4K9l6xAK/ibav2FW3j2HeZc8UcSWB//zyJq7ZdMCmxapsRIdtQXpTE@g6m/RSLasaN/NgrMqKbiuqV4sLbY0TTIP6Y2sSJZM27eqIHX9B9NVXAsuLZVIZm0r8B@AcKtyJDfaA@WthlWWiWIeOxhshf5skexshvGHy/fyrEb/6xc "C (gcc) – Try It Online")
*Port of [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s [JavaScript answer](https://codegolf.stackexchange.com/a/260122/9481)*
[Answer]
# [FunStack](https://github.com/dloscutoff/funstack) alpha, 39 bytes
```
Minus foldl 0 Product map IFrom1 IFrom1
```
Try it at [Replit](https://replit.com/@dloscutoff/funstack)!
### Worked example
```
                4
IFrom1          [1,2,3,4]
IFrom1          [[1],[1,2],[1,2,3],[1,2,3,4]]
Product map     [1,2,6,24]
Minus foldl 0   19
```
where the last bit is
```
Minus          Subtract first argument from second
      foldl    Left-fold on that function
            0  starting with an accumulator value of 0
```
and so our result is -(-(-(-0+1)+2)+6)+24 = 19.
]