[Question]
  [
The [Torian](https://googology.wikia.org/wiki/Torian), \$x!x\$, of a non-negative integer \$x\$ can be recursively defined as
$$
x!0 = x \\
x!n = \prod^x\_{i=1} i!(n-1) = 1!(n-1) \times 2!(n-1) \times \cdots \times x!(n-1)
$$
The Torian is then equal to \$x!x\$ for a given \$x\$. This sequence begins \$0, 1, 2, 24, 331776, ...\$ for \$x = 0, 1, 2, 3, 4, ...\$
Alternatively, you can consider the binary function \$!\$ to be instead \$f(x, y)\$. We then have \$f(x, 0) = x\$ and \$f(x, y) = f(1, y-1) \times f(2, y-1) \times \cdots \times f(x, y-1)\$. You should then calculate \$f(x, x)\$.
You are to take a non-negative integer \$x\$ and output \$x!x\$. You may take input and output in any [convenient method](https://codegolf.meta.stackexchange.com/questions/2447/default-for-code-golf-input-output-methods), and you don't have to worry about outputs exceeding your language's integer limit. This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins
### Test cases
```
x x!x
0  0
1  1
2  2
3  24
4  331776
5  2524286414780230533120
6  18356962141505758798331790171539976807981714702571497465907439808868887035904000000
7  5101262518548258728945891181868950955955001607224762539748030927274644810006571505387259191811206793959788670295182572066866010362135771367947051132012526915711202702574141007954099155897521232723988907041528666295915651551212054155426312621842773666145180823822511666294137239768053841920000000000000000000000000000
```
And [here](https://tio.run/##XY1BCsIwFETXySlm10QjGN0JuUk3gab6QX5K@EJ6@piKRXA3MPPeLKs8Ml9bm9IMyYUim@rA9qYVzWCEgHPPqiR5FUbVSrLEJwK8VnMuIBCjRL4n4x3q0W/od3QIu5O68@St3j2fXut/wWWDl0Is5geSdUg89cth5JEH29ob) is a reference program that produces output for \$0!0\$ to \$11!11\$
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 6 bytes
```
R×\⁸¡Ṫ
```
[Try it online!](https://tio.run/##AR4A4f9qZWxsef//UsOXXOKBuMKh4bmq/8W7w4figqz//zU "Jelly – Try It Online")
# [APL (Dyalog Unicode)](https://www.dyalog.com/), 10 bytes
```
{⊃⌽×\⍣⍵⍳⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///v/pRV/Ojnr2Hp8c86l38qHfro97NQLL2f9qjtgmPevuAsofWGz9qm/iob2pwkDOQDPHwDP6fdmgFUKEpV5qCAQA "APL (Dyalog Unicode) – Try It Online")
The main trick is to observe how the computation of `x!y` progresses as `y` increases.
```
1!0=1    2!0=2        3!0=3            4!0=4                ...
1!1=1    2!1=1*2      3!1=1*2*3        4!1=1*2*3*4          ...
1!2=1!1  2!2=1!1*2!1  3!2=1!1*2!1*3!1  4!2=1!1*2!1*3!1*4!1  ...
1!3=1!2  2!3=1!2*2!2  3!3=1!2*2!2*3!2  4!3=1!2*2!2*3!2*4!2  ...
...
```
Basically going to the next row is just a matter of product scan on the previous row. Therefore, to get the value of `x!x`, we can just run product scan on the range `1..x` `x` times, and extract the last element.
One caveat of this approach is that the 0 case must be checked separately. In Jelly, popping from an empty array gives 0. In APL, `⊃` of the empty vector is 0 (`⊢/` does not work in place of `⊃⌽`).
I have 16-byte J and 14-byte ngn/k answers using the same algorithm. Can you find them? (ngn/k code includes converting 0N to 0)
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
R¡FP
```
[Try it online!](https://tio.run/##y0rNyan8/z/o0EK3gP///5sCAA "Jelly – Try It Online")
```
       (Starting from [n],)
R      Recursively replace each x with [1..x]
 ¡     n times
  F    Flatten
   P   Product
```
For example `R¡` for the input `4` yields
```
[
    [[[1]]],
    [[[1]], [[1], [1, 2]]],
    [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]]],
    [[[1]], [[1], [1, 2]], [[1], [1, 2], [1, 2, 3]], [[1], [1, 2], [1, 2, 3], [1, 2, 3, 4]]]
]
```
and the product of all numbers in that nested list is 331776.
[Answer]
# [Haskell](https://www.haskell.org/), 43 bytes
```
f x=x!x
x!0=x
x!n=product$map(!(n-1))[1..x]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwrZCsYKrQtHAFkTm2RYU5aeUJpeo5CYWaChq5OkaampGG@rpVcT@z03MzFOwVSgoLQkuKfLJU9BTKM7IL1dQUYjWyNTJVMzUVKhRyFSw0VUAqTePjf0PAA "Haskell – Try It Online")
+8 bytes due to the problem needing a function that only takes a single argument. Thanks to @Lynn for pointing that out
Thanks to OVS for pointing out map is shorter than a list comprehension and taking 1 byte off.
My first time ever submitting a haskell answer. I am a beginner so do point out places where I can shorten my code :)
---
# [Haskell](https://www.haskell.org/), 39 bytes
```
f x=x!x
x!0=x
0!_=1
x!n=x!(n-1)*(x-1)!n
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwrZCsYKrQtHAtoLLQDHe1hDIzgOKaeTpGmpqaVQAScW8/7mJmXkKtgoFpSXBJUU@eQp6CsUZ@eUKKgrRGpk6aQqZmgo1CpkKNroK0YZ6euaxsf8B "Haskell – Try It Online")
Thanks to @Alwin for suggesting this version.
[Answer]
# Python 3 48 bytes
```
f=lambda x,y:f(x,y-1)*f(x-1,y)if x*y else(y>0)+x
```
[TIO](https://tio.run/##JYnLCsIwEADv@Yo97tZULIKHgv5LpFldaB7EHLJfH1N6mGFgstZvivfe@bm78N4cNKsr4/C80DRiXqySMLRJwe8/D@2C@rpR51RAQCIUFz8eH7QayEViRbE8ECIjIadSoUrw5nxHXg8hUf8D)
# 55 bytes
if a more conventional input is required. I don't know how to initialize the default 2nd argument to equal the first, so I've rewritten everything as t=x-y without much more thought.
```
f=lambda x,t=0:f(x,t+1)*f(x-1,t-1)if(x-t)*x else(x>t)+x
```
Thanks to Arnauld for saving 3 bytes
[Answer]
# [Factor](https://factorcode.org/), ~~53 45~~ 41 bytes
```
[ dup [1,b] [ cum-product ] repeat last ]
```
[Try it online!](https://tio.run/##Jcw7DsIwEIThPqeYA0AkOgQHQDQ0iMpKsThLsOIX63UBlzeWUn7SP/Miq0na4369XU4IpO9RKC5csLJE9lg4spB3P1KXYtmSol1Fnd2Mwp/K0fZVFlb9ZnFRcR6GI1xSagZzzTCH3XOCga1hnyXN1SomCGcmhafS1QJl9He7ju0P "Factor – Try It Online")
A port of @Bubbler's [answers](https://codegolf.stackexchange.com/a/231277/97916); take the product scan (cumulative product) of `1..x` `x` times and then return the last element.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 43 bytes
Expects and returns a BigInt.
```
f=(x,n=x,g=_=>x?f(x--,~-n)*g():1n)=>n?g():x
```
[Try it online!](https://tio.run/##FYxBCoMwEADvvmILHrI1Kc21dvUpVawJLbIRLWUhpF9PzWWYwzDv8Tvu0/ZaP4bDc87ZkRLNJNrTgzrpnRJj9M8wnr3Cm2Wkjvuikl3YlADBlVsQuBNYW6xpEGIFMAXewzJfluDVUEdJp4Kjr@NxxTRgW6X8Bw "JavaScript (Node.js) – Try It Online")
This actually simplifies down to ...
# [JavaScript (Node.js)](https://nodejs.org), 37 bytes
```
f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1n:x
```
[Try it online!](https://tio.run/##FYzBCoMwEETvfsUWPGSrKc1Vu/VXFGtKi@yKlrIQ4q/HeBnmMY/5Dv9hG9fP8rMsryklT0ZrJkV6cqedz7Rbxqs3u80DNo4bTV5Wo0Bw5xYUHgTOna2qEEIBMApvMk@3Wd6mL4PGyxnZL0M@xNhjW8R0AA "JavaScript (Node.js) – Try It Online")
... which is essentially the same as [Alwin's answer](https://codegolf.stackexchange.com/a/231287/58563).
[Answer]
# [Haskell](https://www.haskell.org/), 41 bytes
```
f n=product$iterate(>>= \x->[1..x])[n]!!n
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz7agKD@lNLlEJbMktSixJFXDzs5WIaZC1y7aUE@vIlYzOi9WUTHvf25iZp6CrUJBUWZeiYKKQm5igUKaAkiJaex/AA "Haskell – Try It Online")
Same idea as my Jelly answer: starting from `[n]`, repeatedly replace each `x` by `1..x`, `n` times, then take the product.
```
  [4]
→ [1,2,3,4]
→ [1,1,2,1,2,3,1,2,3,4]
→ [1,1,1,2,1,1,2,1,2,3,1,1,2,1,2,3,1,2,3,4]
→ [1,1,1,1,2,1,1,1,2,1,1,2,1,2,3,1,1,1,2,1,1,2,1,2,3,1,1,2,1,2,3,1,2,3,4]
→ product: 331776
```
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 27 bytes
```
1##&@@#&//@Nest[Range,#,#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b731BZWc3BQVlNX9/BL7W4JDooMS89VUdZRzlW7X9AUWZeSbSyrl2aA5BbF5ycmFcHlo820DGP/Q8A "Wolfram Language (Mathematica) – Try It Online")
Port of Lynn's solution.
---
### [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes
```
Nest[f1##&@@f~Array~#&,D,#]@#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b73y@1uCQ67f2khYbKymoODml1jkVFiZV1ymo6LjrKsQ7Kav8DijLzSqKVde3SHJRj1eqCkxPz6oIS89JTow10zGP/AwA "Wolfram Language (Mathematica) – Try It Online")
Builds \$x!0...x!x\$:
```
                        D           x => x!0
     f1##&@@f~Array~#&             (x => x!n) => (x => x!(n+1))
Nest[                  , ,#]        x => x!#
                            @#      #!#
```
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), ~~13 12~~ 14 bytes
Saved 1 byte thanks to ngn
Fixed thanks to Razetime
```
{*|0,x*\/1+!x}
```
[Try it online!](https://tio.run/##y9bNz/7/P82qWqvGQKdCK0bfUFuxovZ/mrqi@X8A "K (oK) – Try It Online")
```
{*|0,x*\/1+!x}
           !x  Range [0..x-1]
         1+    Increment range
     x  /      Repeat x times:
      *\       Get the cumulative products of the list
               When this is done y times, we get [1!y, 2!y...x!y]
   0,          Prepend a 0 in case x is 0
 *|            Get the last number (x!y) by reversing and getting the head
```
[Answer]
# JavaScript (ES6), 46 bytes
```
x=>(g=p=>x>1n?x--**p*g(p*y++/i++):x)(i=1n,y=x)
```
[Try it online!](https://tio.run/##FcpBDsIgEADAe1@xxwWK2pvRLr6lqUDWkIW0jaExvh3raS7zmt7TOi9cNiv56VugVslhpEKuukEe1Vqti45Y9G7MmY1Rt6qQaZB@p6payAtg8hswEFzkfjjC9e9R4dMBzFnWnPwp5YjcQ0BWqvu2Hw "JavaScript (Node.js) – Try It Online")
Use
$$ f\left(n\right) = \prod\_{i=1}^n i^{{2n-i-1}\choose{n-1}} $$
with exception
$$ f\left(0\right) = 0 $$
[Answer]
# [R](https://www.r-project.org/), 46 bytes
```
x=scan();i=1:x;prod(i^choose(2*x-i-1,x-1))*!!x
```
[Try it online!](https://tio.run/##Vc3BCsIwEATQe79ii5fdYsRUPcTaL9CjZ6HGFBdKEpKKEfHbozl6eYcZhgnZ@ZmdjRg1e2N7pRRVIxwEjA@rS4VM8IaoB/uXEsPibOIMzzB4bwJcX3DkwNMEp1VOfRkgddzLfep8cDfki747Fw22TRIs5DIJSdTUdcqfasT17xdloS1sCtvCjvIX "R – Try It Online")
Using formula from [tsh's answer](https://codegolf.stackexchange.com/a/231284/55372) (presumably adapted from [OEIS page](https://oeis.org/A068943)).
---
Straightforward recursion:
### [R](https://www.r-project.org/), 50 bytes
```
f=function(x,n=x)"if"(n,prod(sapply(1:x,f,n-1)),x)
```
[Try it online!](https://tio.run/##Fcs9CoAwDEDh3WM4JRDB@jNU6GFEDRQkDVahnr6a5RsevKsmvWOSDHmLekjw3mPlwI9s1qGQhIJt5BaE9Eo75FX1fMEthZikc4hU/gV6bBicMRijMRkz1g8 "R – Try It Online")
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 9 bytes
```
[ɾ?(⁽*r)t
```
[Try it Online!](https://lyxal.pythonanywhere.com?flags=&code=%5B%C9%BE%3F%28%E2%81%BD*r%29t&inputs=5&header=&footer=)
-1 thanks to @AUsername
[Answer]
# [Julia 0.7](http://julialang.org/), ~~32~~ 29 bytes
-3 bytes by MarcMush.
```
<(x,n=x)=n>0?prod(1:x.<n-1):x
```
[Try it online!](https://tio.run/##BcFRCoAgDADQq/i5QUV@CbLVWQorDJkiBbv9fO/9Sz6CGYFOwoos27q3XhP4qAvJ7DGq3bU7ZR@Daz3LVwQIzvyAIqK7JNkA "Julia 0.7 – Try It Online")
Or if we are allowed to take the input as it appears in Torian notation itself (essentially twice), then it becomes:
# [Julia 0.7](http://julialang.org/), 24 bytes
```
x<n=n>0?prod(1:x.<n-1):x
```
[Try it online!](https://tio.run/##yyrNyUw0//@/wibPNs/OwL6gKD9Fw9CqQs8mT9dQ06rif1p@kUKFraGVuUJBUWZeSU6eRlJmukaFpk2FpkJqXsp/AA "Julia 0.7 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jellylanguage), 9 bytes
```
’ß¥ⱮPðṛḷ?
```
[Try It Online!](https://jht.hyper-neutrino.xyz/tio#WyIiLCLigJnDn8Kl4rGuUMOw4bmb4bi3PyIsIjXFu8OH4oKsIiwiIixbXV0=)
-1 byte thanks to caird coinherinaahing
This is a singular dyadic link. The challenge requires taking one input; however, a single dyadic chain within a monadic link will have the argument supplied to both sides so this works just fine.
```
’ß¥ⱮPðṛḷ?    Dyadic Chain
        ?    If
       ḷ     The left argument is truthy
-----ð       Evaluate on the left argument (this is a variadic chain, and its arity changes between runtimes)
   Ɱ         For each in range on the right argument
--¥          Call as dyad:
’            -  Decrement the left argument
 ß           - Recurse (the `¥` is only necessary to make this act as a dyad since it's a variadic actor)
    P        And take the product
      ṛ      Otherwise, just return x
```
[Answer]
# JavaScript, ~~38~~ 36 bytes
~~I still don't understand the challenge but~~ Thanks to Bubbler I understand the challenge a bit better and this port of [Alwin's solution](https://codegolf.stackexchange.com/a/231287/58974) seems to work - be sure to `+1` them too.
Only handles inputs up to `4` as anything bigger will result in an output exceeding JavaScript's [`MAX_SAFE_INTEGER`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER)
```
f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1:x
```
[Try it online!](https://tio.run/##DctBDkAwEEDRq1h2VIWFTRmu0qZUiMwIIrNy9ery5@Xv/vV3uLbzMcTzklJEJRWhAI40yRRzfYagjOozGcC2VlLkSwk2vQxdr7VAYLr5WOqDVyXaFVg4nU@A9AM)
For just one byte more, though, we can handle larger inputs by using BigInts:
```
f=(x,n=x)=>n?x?f(x,~-n)*f(~-x,n):1n:x
```
[Try it online!](https://tio.run/##DctBDkRAEEbhq1h2aS3DEsVFLFrQMhP5SxCplav39PLly/tNz3TN5/e4HWRZYwxstAArcY9Bh5DqdaA8mNcloKZCozHIaZQ/aLWrarTWKs2CS/a13GUzan3GmbfppsKP8BT/)
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 51 bytes
```
f(n){n=g(n,n);}g(x,n){x=n?x?g(x,n-1)*g(x-1,n):1:x;}
```
[Try it online!](https://tio.run/##XVDBboMwDL33KyykSoEGtUC3as1YD9O@Yu2BpgGidaYiTM2G@PUxQylaGymO/fz8Ylv6mZRtmzJ0a4wzhhxd0WTM0lvbGDd20wd@4Hrk@AHh62BtRdNqrOAz0cjcST0BOh1QKVOZ9x3EUC84BBxCDhGHZSNg7kGC31WuMYNcZ7kqYX8szga@TlAgRKG/11UnYsCbj4LKnpSs1OFOM1ySbhSsVo@N6LkyT0qPrJIfqiQydHRna9/CrX16pfvgcPgfR85QmRYlsO4rjQdlqWwhBvcZjP5RRcquTbjzAfBGRMBs1rNduGzh2jiS0mUbfXonbrKGst3Sb1FF6DjwfdmpJErKnOkB/BcgOzVbpKGQg@Hj5CqOzW6QbSZN@yvTY5KZ1j//AQ "C (gcc) – Try It Online")
Port of [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)'s [JavaScript answer](https://codegolf.stackexchange.com/a/231285/9481) (which may be based on [Shaggy](https://codegolf.stackexchange.com/users/58974/shaggy)'s [JavaScript answer](https://codegolf.stackexchange.com/a/231289/58974)) which, in turn, is based on [Alwin's answer](https://codegolf.stackexchange.com/a/231287/58563).
[Answer]
# [Haskell](https://www.haskell.org/), 37 bytes
```
h x=iterate(scanl1(*))(1:[1..])!!x!!x
```
[Try it online!](https://tio.run/##fc2xDsIgEMbxvU/xkTiAkUYmEyM@gZujYSAVLdrShtJ4g@9eW0e1Ltxwv/9R2u7uqmq4gDQxyoit9fQG3cbm3BdpUduWMx6kEuKk8pxMdh2tTy7a5HhX2BAVX45LWpEcgTKMEWProfxg1ZtxtZ3OGPFWNNw0/4vEfq/5OLLa@gCNc5MBbZ@OKR4CcnRl88ACJ@5XnnmBJzx2ElO@MQZSIrqLiy4Ubja84iuctSV@fmKL1Ntqtrp9V8ML "Haskell – Try It Online")
[Product scan method](https://codegolf.stackexchange.com/a/231277/78410) seems to win over other approaches.
[Answer]
# Python 3, 50 bytes
```
t=lambda x,z=0:x*(x-z)and t(x-1,z-1)*t(x,z+1)or x
```
Using the trick of using parameter z=x-y from @Alwin's answer. Before that, I had the 59 byte version
```
t=lambda x,y=-1:x*(y:=(y,x)[y<0])and t(x-1,y)*t(x,y-1)or x
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 22 bytes
```
≔ＥＮ⊕ιθＦθＵＭθΠ…θ⊕λＩ∧Ｌθ⊟θ
```
[Try it online!](https://tio.run/##TYw7DsMgEAV7n4JykZwylSuLylIS@QoEiEGC5R8ppyfrVHnlaOYpK4uK0o@x1uoOhLtMsGHq7dHD0xTgM9tQFRMMNqPBcQKZL9MrFgaZM/JFDEGihjyzvUTdVQPxUd4IG9MJ/3vPacu0F4dkydpgpfJm8GiW7ujhbH7SGNdxefsv "Charcoal – Try It Online") Link is to verbose version of code. Explanation: Port of @Bubbler's answer.
```
≔ＥＮ⊕ιθ
```
Start with a range from `1` to `n`.
```
Ｆθ
```
Repeat `n` times...
```
ＵＭθΠ…θ⊕λ
```
... calculate the cumulative products.
```
Ｉ∧Ｌθ⊟θ
```
Output the last one, unless `n=0`, in which case just output `0`.
[Answer]
# [05AB1E (legacy)](https://github.com/Adriandmen/05AB1E/wiki/Commands), 5 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
FL}˜P
```
Port of [*@Lynn*'s Jelly answer](https://codegolf.stackexchange.com/a/231303/52210), so make sure to upvote him/her as well!
[Try it online](https://tio.run/##MzBNTDJM/f/fzaf29JyA//@NAQ) or [verify the first \$[0,7]\$ test cases](https://tio.run/##MzBNTDJM/W9@bJKfvZLCo7ZJCkr2fi7/3XxqT88J@K/zHwA).
**Explanation:**
```
F    # Loop the (implicit) input amount of times:
 L   #  Transform each integer `n` into a [1,n] ranged list
     #  (which uses the implicit input in the first iteration)
}˜   # After the loop: flatten the nested lists
  P  # And take the product of all integers
     # (after which the result is output implicitly)
```
Uses the legacy version of 05AB1E, because [the new version's `˜` doesn't work on a single integer for input \$x=0\$](https://tio.run/##yy9OTMpM/f/fzaf29JyA//8NAA).
[Answer]
# [ayr](https://github.com/ZippyMagician/ayr), 8 bytes (2 methods)
Method 1:
```
:*/,~$:`
```
Method 2 (doesn't work for N=0):
```
]/]*\$:~
```
# Explanation
```
:       Non J-style train
   ~$:  1-range on each scalar val
      ` Commute input (pass to both sides)
*/,     Product of all scalars
```
Dyadic `A u$: B` is call `u` on previous iteration `A` times with starting value `B`
```
       ~    1-range of N
   *\$:     Repeatedly foldl with multiplication
  ]         N times
]/          Rightmost argument
```
[Answer]
# [Uiua](https://uiua.org) [SBCS](https://tinyurl.com/Uiua-SBCS-Jan-14), 12 bytes
```
⬚0⊢⇌⍥\×:+1⇡.
```
[Try it!](https://uiua.org/pad?src=0_8_0__ZiDihpAg4qyaMOKKouKHjOKNpVzDlzorMeKHoS4KCuKItWbih6E2Cg==)
Pretty much a port of Bubbler's [Jelly/APL answers](https://codegolf.stackexchange.com/a/231277/97916).
]